benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f9952138-48f6-5890-a570-93b5377a0e38

Problem

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

complete prompt

import collections
import pandas as pd

def task_func(my_tuple, path_csv_files):
    """
    Count the occurrences of each value in the specified columns in multiple CSV files.

    Parameters:
    my_tuple (tuple): The tuple of column names.
    path_csv_files (list of string): The list of csv files to read.

    Returns:
    dict: A dictionary where keys are column names and values are dictionaries 
        with unique values in the column as keys and their counts as values.

    Requirements:
    - collections
    - pandas

    Example:
    >>> from unittest.mock import MagicMock
    >>> import pandas as pd
    >>> df1 = pd.DataFrame({'Country': ['USA', 'Canada', 'USA'], 'Gender': ['Male', 'Female', 'Male']})
    >>> df2 = pd.DataFrame({'Country': ['UK', 'USA', 'Germany'], 'Gender': ['Male', 'Male', 'Female']})
    >>> pd.read_csv = MagicMock(side_effect=[df1, df2])
    >>> result = task_func(('Country', 'Gender'), ['file1.csv', 'file2.csv'])
    >>> print(result['Country'])
    Counter({'USA': 3, 'Canada': 1, 'UK': 1, 'Germany': 1})
    """

instruct prompt

Count the occurrences of each value in the specified columns in multiple CSV files.
The function should output with:
    dict: A dictionary where keys are column names and values are dictionaries
    with unique values in the column as keys and their counts as values.
You should write self-contained code starting with:

Code

import collections
import pandas as pd
def task_func(my_tuple, path_csv_files):

code prompt

Code

import collections
import pandas as pd
def task_func(my_tuple, path_csv_files):

entry point

task_func

libs

  • pandas
  • collections

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