benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf afdeb611-6532-5d85-9415-6618be7f54c8
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import numpy as np
import pandas as pd
def task_func(products, n_samples=100, sales_lower=50, sales_upper=200, profit_margin_min=0.1, profit_margin_max=0.5, random_seed=42):
"""
Generate a sales report with randomly simulated sales and profit data for a given list of products.
The data is aggregated by product and sorted by total profit in descending order.
Parameters:
- products (list of str): List of product names.
- n_samples (int): The number of data points to generate for the report. Default is 100.
- sales_lower (int): The minimum sales value for the random generation. Default is 50.
- sales_upper (int): The maximum sales value for the random generation. Default is 200.
- profit_margin_min (float): The minimum profit margin as a fraction of sales. Default is 0.1.
- profit_margin_max (float): The maximum profit margin as a fraction of sales. Default is 0.5.
- random_seed (int): Seed for the random number generator to ensure reproducibility. Default is 42.
Returns:
pd.DataFrame: A DataFrame containing aggregated sales and profit data for each product, sorted by profit.
Raises:
ValueError: If n_samples is not a positive integer, or if sales_lower is greater than sales_upper.
TypeError: If products is not a list of strings, or if sales_lower, sales_upper, profit_margin_min, or profit_margin_max are not numeric.
Requirements:
- numpy
- pandas
Example:
>>> products = ["iPhone", "iPad", "Macbook", "Airpods", "Apple Watch"]
>>> report = task_func(products, n_samples=50, sales_lower=100, sales_upper=150, profit_margin_min=0.2, profit_margin_max=0.4, random_seed=42)
>>> print(report)
Product Sales Profit
2 Macbook 1561 444.826709
3 iPad 1383 401.925334
0 Airpods 1297 381.482713
1 Apple Watch 1123 308.078536
4 iPhone 921 294.013887
"""
instruct prompt
Generate a sales report with randomly simulated sales and profit data for a given list of products. The data is aggregated by product and sorted by total profit in descending order.
The function should raise the exception for: ValueError: If n_samples is not a positive integer, or if sales_lower is greater than sales_upper. TypeError: If products is not a list of strings, or if sales_lower, sales_upper, profit_margin_min, or profit_margin_max are not numeric.
The function should output with:
pd.DataFrame: A DataFrame containing aggregated sales and profit data for each product, sorted by profit.
You should write self-contained code starting with:
Code
import numpy as np
import pandas as pd
def task_func(products, n_samples=100, sales_lower=50, sales_upper=200, profit_margin_min=0.1, profit_margin_max=0.5, random_seed=42):
code prompt
Code
import numpy as np
import pandas as pd
def task_func(products, n_samples=100, sales_lower=50, sales_upper=200, profit_margin_min=0.1, profit_margin_max=0.5, random_seed=42):
entry point
task_func
libs
- pandas
- numpy
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