benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf ecf539c6-fddd-50ad-95e0-4a070c1a2f2d

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(data, columns=['Name', 'Age', 'Occupation'], fill_missing=False, num_range=(0, 100), seed=None):
    """
    Create a Pandas DataFrame from a list of tuples, each representing a row.
    Tuples of unequal lengths are allowed, and missing elements are filled with None.
    Optionally, missing numeric values can be filled with random data.

    Parameters:
    data (list of tuples): Each tuple contains the data for each row.
                           Elements in tuples represent values corresponding to the columns parameter.
    columns (list of str): List of column names for the DataFrame.
                           Defaults to ['Name', 'Age', 'Occupation'].
    fill_missing (bool): If True, fill missing numeric values with random data.
                         Defaults to False.
    num_range (tuple): Range (min, max) of random numbers for filling missing values.
                       Defaults to (0, 100).
    seed (int): Optional seed for random number generator for reproducibility.
                Defaults to None.

    Returns:
    DataFrame: A pandas DataFrame with specified columns.
               Missing elements are represented as None or filled with random data.

    Requirements:
    - pandas
    - random

    Example:
    >>> data = [('John', 25, 'Engineer'), ('Alice', ), ('Bob', )]
    >>> df = task_func(data, fill_missing=True, num_range=(0, 10), seed=42)
    >>> print(df)
        Name   Age Occupation
    0   John  25.0   Engineer
    1  Alice  10.0       None
    2    Bob   1.0       None

    >>> data = [('Mango', 20), ('Apple', ), ('Banana', )]
    >>> df = task_func(data, columns=['Fruit', 'Quantity'], fill_missing=False, seed=42)
    >>> print(df)
        Fruit  Quantity
    0   Mango      20.0
    1   Apple       NaN
    2  Banana       NaN
    """

instruct prompt

Create a Pandas DataFrame from a list of tuples, each representing a row. Tuples of unequal lengths are allowed, and missing elements are filled with None. Optionally, missing numeric values can be filled with random data. >>> data = [('Mango', 20), ('Apple', ), ('Banana', )] >>> df = task_func(data, columns=['Fruit', 'Quantity'], fill_missing=False, seed=42) >>> print(df) Fruit  Quantity 0   Mango      20.0 1   Apple       NaN 2  Banana       NaN
The function should output with:
    DataFrame: A pandas DataFrame with specified columns.
    Missing elements are represented as None or filled with random data.
You should write self-contained code starting with:

Code

import pandas as pd
import random
def task_func(data, columns=['Name', 'Age', 'Occupation'], fill_missing=False, num_range=(0, 100), seed=None):

code prompt

Code

import pandas as pd
import random
def task_func(data, columns=['Name', 'Age', 'Occupation'], fill_missing=False, num_range=(0, 100), seed=None):

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