benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 74545691-5418-58b3-afea-8cb14bb75255

Problem

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

complete prompt

import pandas as pd
import numpy as np
from random import choice

# Constants
DATA_TYPES = [str, int, float, list, tuple, dict, set]


def task_func(rows, columns):
    """
    Generates a DataFrame with a specified number of rows and columns, populated with randomly generated data.
    Each column's data type is randomly selected from a set of Python data types,
    including primitive and complex structures.

    Parameters:
    rows (int): Number of rows in the generated DataFrame.
    columns (int): Number of columns in the generated DataFrame. Each column is assigned a random data type.

    DataFrame: A DataFrame in which each column's data type could be one of the following,
    with random content generated accordingly:
    - str: Random strings of 5 lowercase alphabetic characters.
    - int: Random integers from 0 to 9.
    - float: Random floats derived by converting integers from 0 to 9 into float.
    - list: Lists of random length (1 to 5) containing integers from 0 to 9.
    - tuple: Tuples of random length (1 to 5) containing integers from 0 to 9.
    - dict: Dictionaries with a random number (1 to 5) of key-value pairs, keys and values are integers from 0 to 9.
    - set: Sets of random size (1 to 5) containing unique integers from 0 to 9.

    Returns:
    pd.DataFrame: A DataFrame with the specified number of rows and columns named 'col0', 'col1', etc., containing randomly generated data.

    Requirements:
    - pandas
    - numpy
    - random

    Example:
    >>> df = task_func(2, 3)
    >>> print(df.shape)
    (2, 3)
    >>> isinstance(df, pd.DataFrame)
    True
    """

instruct prompt

Generates a DataFrame with a specified number of rows and columns, populated with randomly generated data. Each column's data type is randomly selected from a set of Python data types, including primitive and complex structures. DataFrame: A DataFrame in which each column's data type could be one of the following, with random content generated accordingly: - str: Random strings of 5 lowercase alphabetic characters. - int: Random integers from 0 to 9. - float: Random floats derived by converting integers from 0 to 9 into float. - list: Lists of random length (1 to 5) containing integers from 0 to 9. - tuple: Tuples of random length (1 to 5) containing integers from 0 to 9. - dict: Dictionaries with a random number (1 to 5) of key-value pairs, keys and values are integers from 0 to 9. - set: Sets of random size (1 to 5) containing unique integers from 0 to 9.
The function should output with:
    pd.DataFrame: A DataFrame with the specified number of rows and columns named 'col0', 'col1', etc., containing randomly generated data.
You should write self-contained code starting with:

Code

import pandas as pd
import numpy as np
from random import choice
# Constants
DATA_TYPES = [str, int, float, list, tuple, dict, set]
def task_func(rows, columns):

code prompt

Code

import pandas as pd
import numpy as np
from random import choice
# Constants
DATA_TYPES = [str, int, float, list, tuple, dict, set]
def task_func(rows, columns):

entry point

task_func

libs

  • pandas
  • numpy
  • 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