benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf ff9df5d3-1e8c-5d8c-8ce5-895aabf55a1b

Problem

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

complete prompt

import pandas as pd
from statistics import mean


def task_func(df: pd.DataFrame) -> dict:
    """
    Convert a Pandas DataFrame into a dictionary of generator objects in which 
    each generator generates a sequence of tuples that contain a unique name 
    and the corresponding average score for that name.

    Parameters:
    df (DataFrame): The DataFrame containing 'Name' (string) and 'Score' (number) columns to analyze.

    Returns:
    dict: A dictionary of generator objects. Each generator generates a tuple 
          containing a unique name and the corresponding average score for that name.

    Raises:
    ValueError: If the DataFrame does not have the 'Name' and 'Score' columns.

    Requirements:
    - pandas
    - statistics

    Example:
    >>> df_sample = pd.DataFrame({
    ...     'Name': ['Tom', 'Nick', 'John', 'Tom', 'John'],
    ...     'Score': [85, 79, 90, 88, 82]
    ... })
    >>> gen_dict = task_func(df_sample)
    >>> {key: next(value) for key, value in gen_dict.items()}
    {'John': ('John', 86), 'Nick': ('Nick', 79), 'Tom': ('Tom', 86.5)}

    >>> df_sample = pd.DataFrame({
    ...     'Name': ['Micky', 'Donald', 'Girl'],
    ...     'Score': [25.2, 9, -1]
    ... })
    >>> gen_dict = task_func(df_sample)
    >>> {key: next(value) for key, value in gen_dict.items()}
    {'Donald': ('Donald', 9.0), 'Girl': ('Girl', -1.0), 'Micky': ('Micky', 25.2)}
    """

instruct prompt

Convert a Pandas DataFrame into a dictionary of generator objects in which each generator generates a sequence of tuples that contain a unique name and the corresponding average score for that name. >>> df_sample = pd.DataFrame({ ...     'Name': ['Micky', 'Donald', 'Girl'], ...     'Score': [25.2, 9, -1] ... }) >>> gen_dict = task_func(df_sample) >>> {key: next(value) for key, value in gen_dict.items()} {'Donald': ('Donald', 9.0), 'Girl': ('Girl', -1.0), 'Micky': ('Micky', 25.2)}
The function should raise the exception for: ValueError: If the DataFrame does not have the 'Name' and 'Score' columns.
The function should output with:
    dict: A dictionary of generator objects. Each generator generates a tuple
    containing a unique name and the corresponding average score for that name.
You should write self-contained code starting with:

Code

import pandas as pd
from statistics import mean
def task_func(df: pd.DataFrame) -> dict:

code prompt

Code

import pandas as pd
from statistics import mean
def task_func(df: pd.DataFrame) -> dict:

entry point

task_func

libs

  • statistics
  • pandas

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