benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b310c610-1cae-5e9d-907a-1c83e7b17540

Problem

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

complete prompt

import pandas as pd
from collections import Counter

def task_func(df):
    """
    Calculate the frequency of combinations of elements in a DataFrame.
    The function adds a 'combination' column to the DataFrame, which is the combination of items in each row.
    It then calculates the frequency of each combination.
    
    Parameters:
    - df (pandas.DataFrame): The input DataFrame with columns 'item1', 'item2', 'item3', 'item4', 'item5'.
    
    Returns:
    - dict: A dictionary containing the frequency of all combination.

    Requirements:
    - pandas
    - collections

    Example:
    >>> df = pd.DataFrame({'item1': ['a', 'b', 'a'], 'item2': ['b', 'c', 'b'], 'item3': ['c', 'd', 'c'], 'item4': ['d', 'e', 'd'], 'item5': ['e', 'f', 'e']})
    >>> task_func(df)
    {('a', 'b', 'c', 'd', 'e'): 2, ('b', 'c', 'd', 'e', 'f'): 1}
    """

instruct prompt

Calculate the frequency of combinations of elements in a DataFrame. The function adds a 'combination' column to the DataFrame, which is the combination of items in each row. It then calculates the frequency of each combination.
The function should output with:
    dict: A dictionary containing the frequency of all combination.
You should write self-contained code starting with:

Code

import pandas as pd
from collections import Counter
def task_func(df):

code prompt

Code

import pandas as pd
from collections import Counter
def task_func(df):

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