benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 65be64bb-1e9c-5cbe-8ac0-9a86dd294a99

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(file_path: str, column_name: str) -> pd.DataFrame:
    """
    Load a CSV file into a Pandas DataFrame, replace all occurrences of the string '\n' with the string '<br>'
    in the specified column, and encode the specified column as a categorical variable using LabelEncoder from sklearn.
    
    Parameters:
    - file_path (str): The path to the CSV file to be read.
    - column_name (str): The name of the column in which to replace '\n' and to encode.
    
    Returns:
    pd.DataFrame: The updated and encoded Pandas DataFrame.
    
    Requirements:
    - pandas
    - sklearn.preprocessing.LabelEncoder
    
    Example:
    >>> df = task_func('data.csv', 'Category')
    >>> print(df.head())
    """

instruct prompt

Load a CSV file into a Pandas DataFrame, replace all occurrences of the string '\n' with the string '<br>' in the specified column, and encode the specified column as a categorical variable using LabelEncoder from sklearn.
The function should output with:
    pd.DataFrame: The updated and encoded Pandas DataFrame.
You should write self-contained code starting with:

Code

import pandas as pd
from sklearn.preprocessing import LabelEncoder
def task_func(file_path: str, column_name: str) -> pd.DataFrame:

code prompt

Code

import pandas as pd
from sklearn.preprocessing import LabelEncoder
def task_func(file_path: str, column_name: str) -> pd.DataFrame:

entry point

task_func

libs

  • pandas
  • sklearn

Discussion

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

Official source

initial import