from datasets import loaddataset# Login using e.g. huggingface-cli login to access this…
- User
from datasets import load_dataset# Login using e.g. huggingface-cli login to access this dataset ds = load_dataset("lmarena-ai/arena-human-preference-140k")How can I get specific column of the dataset?
Assistant
To get a specific column from your Hugging Face dataset, you can use several approaches depending on what you want to achieve:Method 1: Access column directly (returns a list) pythonfrom datasets import load_dataset
ds = load_dataset("lmarena-ai/arena-human-preference-140k")
Get a specific column from the train split (returns a list)
column_data = ds['train']['column_name']Method 2: Use select_columns() to create a new dataset with specific columns python# Keep only specific columns in the dataset filtered_ds = ds.select_columns(['column1', 'column2'])
Or for a single column
single_column_ds = ds.select_columns(['column_name'])Method 3: Use map() to extract and transform columns python# Extract a column and potentially transform it def extract_column(example): return {'extracted': example['column_name']}
new_ds = ds.map(extract_column)Method 4: Convert to pandas and access columns python# Convert to pandas DataFrame for easier column manipulation df = ds['train'].to_pandas() column_data = df['column_name']Example with the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.