benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 6241e9be-6da4-5637-9828-bda1701e1526
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 randint, uniform, seed
def task_func(categories=None, months=None, random_seed=42):
"""
Generates a DataFrame with simulated monthly sales data for various product categories, ensuring reproducibility through the use of a random seed.
Parameters:
categories (list of str, optional): A list specifying the product categories to include in the report. If not provided, defaults to ['Electronics', 'Clothing', 'Home & Kitchen', 'Books', 'Beauty & Personal Care'].
months (list of str, optional): A list specifying the months to include in the report. If not provided, defaults to ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'].
random_seed (int, optional): The seed value for the random number generator to ensure the reproducibility of the sales data. Defaults to 42.
Returns:
pandas.DataFrame: A DataFrame with three columns: 'Month', 'Category', and 'Sales'. The 'Sales' values are floating-point numbers in the range [100, 501), generated by the formula: randint(100, 500) + uniform(0, 1), ensuring sales values are diverse yet consistent upon repeated executions with the same seed.
Raises:
ValueError: If either 'categories' or 'months' is not provided as a list or if either is an empty list.
Notes:
- The function sets the random seed at the beginning of execution to ensure that the generated sales data is the same for any given seed value.
- The sales data for each category is generated for each month, creating a comprehensive report that spans all specified categories and months.
Requirements:
- pandas
- random
Example:
>>> report = task_func()
>>> print(report.head())
Month Category Sales
0 January Electronics 427.111331
1 January Clothing 479.275029
2 January Home & Kitchen 214.139538
3 January Books 152.676699
4 January Beauty & Personal Care 379.086939
"""
instruct prompt
Generates a DataFrame with simulated monthly sales data for various product categories, ensuring reproducibility through the use of a random seed.
Note that: Notes: The function sets the random seed at the beginning of execution to ensure that the generated sales data is the same for any given seed value. The sales data for each category is generated for each month, creating a comprehensive report that spans all specified categories and months.
The function should raise the exception for: ValueError: If either 'categories' or 'months' is not provided as a list or if either is an empty list.
The function should output with:
pandas.DataFrame: A DataFrame with three columns: 'Month', 'Category', and 'Sales'. The 'Sales' values are floating-point numbers in the range [100, 501), generated by the formula: randint(100, 500) + uniform(0, 1), ensuring sales values are diverse yet consistent upon repeated executions with the same seed.
You should write self-contained code starting with:
Code
import pandas as pd
from random import randint, uniform, seed
def task_func(categories=None, months=None, random_seed=42):
code prompt
Code
import pandas as pd
from random import randint, uniform, seed
def task_func(categories=None, months=None, random_seed=42):
entry point
task_func
libs
- pandas
- random
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
initial import