benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 47631d8a-1940-5dc9-9023-5a8e511a496f
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import pandas as pd
from sklearn.preprocessing import LabelEncoder
def task_func(data):
"""
Transforms categorical data into a numerical format suitable for machine learning algorithms using sklearn's
LabelEncoder. This function generates a DataFrame that pairs original categorical values with their numerical
encodings.
Parameters:
data (list): List of categorical data to be encoded.
Returns:
DataFrame: A DataFrame with columns 'Category' and 'Encoded', where 'Category' is the original data and 'Encoded'
is the numerical representation.
Requirements:
- pandas
- sklearn
Example:
>>> df = task_func(['A', 'B', 'C', 'A', 'D', 'E', 'B', 'C'])
>>> print(df.to_string(index=False))
Category Encoded
A 0
B 1
C 2
A 0
D 3
E 4
B 1
C 2
"""
instruct prompt
Transforms categorical data into a numerical format suitable for machine learning algorithms using sklearn's LabelEncoder. This function generates a DataFrame that pairs original categorical values with their numerical encodings.
The function should output with:
DataFrame: A DataFrame with columns 'Category' and 'Encoded', where 'Category' is the original data and 'Encoded'
is the numerical representation.
You should write self-contained code starting with:
Code
import pandas as pd
from sklearn.preprocessing import LabelEncoder
def task_func(data):
code prompt
Code
import pandas as pd
from sklearn.preprocessing import LabelEncoder
def task_func(data):
entry point
task_func
libs
- pandas
- sklearn
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import