benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf c39432e7-f946-5e1a-8510-e8aad8838e71
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
import statistics
def task_func(rows, columns=['A', 'B', 'C', 'D', 'E', 'F'], seed=42):
"""
Create a Pandas DataFrame with a specified number of rows and six columns (default A-F),
each filled with random numbers between 1 and 100, using a specified seed for reproducibility.
Additionally, calculate the mean and median for each column.
Parameters:
- rows (int): The number of rows in the DataFrame. Must be a positive integer greater than 0.
- columns (list, optional): Column names for the DataFrame. Defaults to ['A', 'B', 'C', 'D', 'E', 'F'].
- seed (int, optional): Seed for the random number generator. Defaults to 42.
Returns:
- DataFrame: A pandas DataFrame with the generated data.
- dict: A dictionary containing the calculated mean and median for each column.
The dictionary format is:
{
'ColumnName': {
'mean': MeanValue,
'median': MedianValue
}, ...
}
where 'ColumnName' is each of the specified column names, 'MeanValue' is the calculated mean,
and 'MedianValue' is the calculated median for that column.
Raises:
- ValueError: If 'rows' is not a positive integer greater than 0.
Requirements:
- numpy
- pandas
- statistics
Example:
>>> df, stats = task_func(10)
>>> print(df)
A B C D E F
0 52 93 15 72 61 21
1 83 87 75 75 88 100
2 24 3 22 53 2 88
3 30 38 2 64 60 21
4 33 76 58 22 89 49
5 91 59 42 92 60 80
6 15 62 62 47 62 51
7 55 64 3 51 7 21
8 73 39 18 4 89 60
9 14 9 90 53 2 84
>>> print(stats)
{'A': {'mean': 47, 'median': 42.5}, 'B': {'mean': 53, 'median': 60.5}, 'C': {'mean': 38.7, 'median': 32.0}, 'D': {'mean': 53.3, 'median': 53.0}, 'E': {'mean': 52, 'median': 60.5}, 'F': {'mean': 57.5, 'median': 55.5}}
"""
instruct prompt
Create a Pandas DataFrame with a specified number of rows and six columns (default A-F), each filled with random numbers between 1 and 100, using a specified seed for reproducibility. Additionally, calculate the mean and median for each column.
The function should raise the exception for: ValueError: If 'rows' is not a positive integer greater than 0.
The function should output with:
DataFrame: A pandas DataFrame with the generated data.
dict: A dictionary containing the calculated mean and median for each column.
The dictionary format is:
{
'ColumnName': {
'mean': MeanValue,
'median': MedianValue
}, ...
}
where 'ColumnName' is each of the specified column names, 'MeanValue' is the calculated mean,
and 'MedianValue' is the calculated median for that column.
You should write self-contained code starting with:
Code
import numpy as np
import pandas as pd
import statistics
def task_func(rows, columns=['A', 'B', 'C', 'D', 'E', 'F'], seed=42):
code prompt
Code
import numpy as np
import pandas as pd
import statistics
def task_func(rows, columns=['A', 'B', 'C', 'D', 'E', 'F'], seed=42):
entry point
task_func
libs
- statistics
- 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