benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf cf95ec6c-43d1-5172-8995-c90eddf70af1

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(num_rows=100, categories=["a", "b", "c", "d", "e"], random_seed=42):
    """
    Create a Pandas DataFrame with specified number of rows. Each row contains a randomly
    selected category from the provided categories list and a random integer between 1 and 100.

    The function also generates a bar chart visualizing the counts of each category in the DataFrame
    and returns both the DataFrame and the bar chart.

    Parameters:
    - num_rows (int): Number of rows in the DataFrame. Default is 100. Must be at least 1.
    - categories (list): List of categories to choose from. Default is ['a', 'b', 'c', 'd', 'e'].
    - random_seed (int): Seed for random number generation to ensure reproducibility. Default is 42.

    Returns:
    - pd.DataFrame: A pandas DataFrame with randomly generated category data.
    - matplotlib.pyplot.Axes: A bar chart visualizing the category counts, with the title 'Category Counts'.

    Raises:
    - ValueError: If num_rows is less than 1.
    
    Requirements:
    - pandas
    - random

    Example:
    >>> df, ax = task_func(num_rows=5)
    >>> df
      Category  Value
    0        a     18
    1        a     95
    2        c     14
    3        b     87
    4        b     95
    """

instruct prompt

Create a Pandas DataFrame with specified number of rows. Each row contains a randomly selected category from the provided categories list and a random integer between 1 and 100. The function also generates a bar chart visualizing the counts of each category in the DataFrame and returns both the DataFrame and the bar chart.
The function should raise the exception for: ValueError: If num_rows is less than 1.
The function should output with:
    pd.DataFrame: A pandas DataFrame with randomly generated category data.
    matplotlib.pyplot.Axes: A bar chart visualizing the category counts, with the title 'Category Counts'.
You should write self-contained code starting with:

Code

import pandas as pd
import random
def task_func(num_rows=100, categories=["a", "b", "c", "d", "e"], random_seed=42):

code prompt

Code

import pandas as pd
import random
def task_func(num_rows=100, categories=["a", "b", "c", "d", "e"], random_seed=42):

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