benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf c4d036b9-a88f-5f13-ae8b-2c39b710a6b2

Problem

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

complete prompt

import pandas as pd
import random

def task_func(df):
    """
    Generate a DataFrame that contains savegames for a number of games between different teams.
    Each row of the input DataFrame represents a match, and contains two teams and their respective scores.
    The function adds a 'winner' column to the DataFrame, which is the team with the highest score in each match.
    If the scores are equal, the winner is should be randomly decided.
    
    Parameters:
    - df (pandas.DataFrame): The input DataFrame with columns 'team1', 'team2', 'score1', 'score2'.

    Requirements:
    - pandas
    - random
    
    Returns:
    - df (pandas.DataFrame): The DataFrame with the added 'winner' column.
    
    Example:
    >>> import numpy as np
    >>> import pandas as pd
    >>> df = pd.DataFrame({'team1': np.random.choice(['Team A', 'Team B', 'Team C', 'Team D', 'Team E'], 20),
    ...                    'team2': np.random.choice(['Team A', 'Team B', 'Team C', 'Team D', 'Team E'], 20),
    ...                    'score1': np.random.randint(0, 10, 20),
    ...                    'score2': np.random.randint(0, 10, 20)})
    >>> df = task_func(df)
    >>> assert 'winner' in df.columns
    >>> assert df['winner'].dtype == object
    >>> assert all(winner in ['Team A', 'Team B', 'Team C', 'Team D', 'Team E'] for winner in df['winner'])
    """

instruct prompt

Generate a DataFrame that contains savegames for a number of games between different teams. Each row of the input DataFrame represents a match, and contains two teams and their respective scores. The function adds a 'winner' column to the DataFrame, which is the team with the highest score in each match. If the scores are equal, the winner is should be randomly decided.
The function should output with:
    df (pandas.DataFrame): The DataFrame with the added 'winner' column.
You should write self-contained code starting with:

Code

import pandas as pd
import random
def task_func(df):

code prompt

Code

import pandas as pd
import random
def task_func(df):

entry point

task_func

libs

  • pandas
  • random

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