benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 202a199f-b2d4-5ea2-9426-8baccb6bba4a

Problem

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

complete prompt

import pandas as pd
from random import seed, choices

def task_func(L, num_dataframes=5, random_seed=None):
    """
    Generate a specified number of Pandas DataFrames from a list of lists "L".
    Each DataFrame has the same column names randomly chosen from lowercase English
    letters and 3 rows sampled from 'L'. Then, find the common
    rows between all generated DataFrames.

    If L is empty, an empty dataframe is returend.

    Parameters:
    L (list of lists): Input list of lists to be used as rows in the DataFrame.
    num_dataframes (int, optional): Number of DataFrames to generate. Defaults to 5.
    random_seed (int, optional): Seed for the random number generator for reproducibility. Defaults to None

    Returns:
    DataFrame: A pandas DataFrame with the common rows between all generated DataFrames.
    list of DataFrame: A list of all generated DataFrames.
    

    Requirements:
    - pandas
    - random

    Example:
    >>> L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]
    >>> common_rows, df_list = task_func(L, num_dataframes=3, random_seed=123)
    >>> print(common_rows)
        b   c   k
    0  14  65  76
    1  14  22  46
    4   2   5   6
    >>> print(df_list)
    [    b   c   k
    0  14  65  76
    1  14  22  46
    2  14  65  76,     b   c   k
    0   7  12  33
    1   2   5   6
    2  14  22  46,     b   c   k
    0  14  65  76
    1   2   5   6
    2   2   5   6]

    >>> L = [[1, '65', 76], [2, '5', 6]]
    >>> common_rows, df_list = task_func(L, num_dataframes=1, random_seed=1)
    >>> print(common_rows)
       d   w   t
    0  1  65  76
    >>> print(df_list)
    [   d   w   t
    0  1  65  76
    1  1  65  76
    2  1  65  76]
    """

instruct prompt

Generate a specified number of Pandas DataFrames from a list of lists "L". Each DataFrame has the same column names randomly chosen from lowercase English letters and 3 rows sampled from 'L'. Then, find the common rows between all generated DataFrames. If L is empty, an empty dataframe is returend. >>> L = [[1, '65', 76], [2, '5', 6]] >>> common_rows, df_list = task_func(L, num_dataframes=1, random_seed=1) >>> print(common_rows) d   w   t 0  1  65  76 >>> print(df_list) [   d   w   t 0  1  65  76 1  1  65  76 2  1  65  76]
The function should output with:
    DataFrame: A pandas DataFrame with the common rows between all generated DataFrames.
    list of DataFrame: A list of all generated DataFrames.
You should write self-contained code starting with:

Code

import pandas as pd
from random import seed, choices
def task_func(L, num_dataframes=5, random_seed=None):

code prompt

Code

import pandas as pd
from random import seed, choices
def task_func(L, num_dataframes=5, random_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