benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf e06485b7-f8f0-5c3a-a7d4-994a0ad7bb9d

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import os
import pandas as pd
import numpy as np


def task_func(data_dir: str, csv_file: str) -> pd.DataFrame:
    """
    Load a CSV file into a pandas DataFrame and replace the NaN values in
    numeric columns with the mean of the corresponding column.
    The resulting DataFrame is returned.

    If an empty csv is passed, an empty DataFrame is returned.

    Parameters:
    - data_dir (str): The path to the directory containing the CSV file.
    - csv_file (str): The name of the CSV file to be processed.

    Returns:
    pd.DataFrame: A pandas DataFrame with the processed data.

    Raises:
    FileNotFoundError: If csv_file does not exist.

    Requirements:
    - os
    - pandas
    - numpy
    
    Example:
    >>> df = task_func("/path/to/data/directory", "file.csv")
    >>> print(df)
         Fruit     Taste     Cost
    0    Apple      Good        1
    1   Orange       NaN        2
    2  Avocado       Bad        1.667
    3  Coconut     Tasty        2
    """

instruct prompt

Load a CSV file into a pandas DataFrame and replace the NaN values in numeric columns with the mean of the corresponding column. The resulting DataFrame is returned. If an empty csv is passed, an empty DataFrame is returned.
The function should raise the exception for: FileNotFoundError: If csv_file does not exist.
The function should output with:
    pd.DataFrame: A pandas DataFrame with the processed data.
You should write self-contained code starting with:

Code

import os
import pandas as pd
import numpy as np
def task_func(data_dir: str, csv_file: str) -> pd.DataFrame:

code prompt

Code

import os
import pandas as pd
import numpy as np
def task_func(data_dir: str, csv_file: str) -> pd.DataFrame:

entry point

task_func

libs

  • pandas
  • numpy
  • os

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