benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 76481762-a399-51b2-bba2-318afe308543
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
from datetime import timedelta
def task_func(start_date, end_date, random_seed=42):
"""
Generate and plot weather data for a specified date range.
This function creates a DataFrame containing simulated daily weather data
within the specified date range. It generates random values for temperature,
humidity, and wind speed for each day. The function also plots these parameters
over the date range and returns both the DataFrame and the plot object.
Parameters:
- start_date (datetime): The start date for the data generation.
- end_date (datetime): The end date for the data generation.
- random_seed (int, optional): Seed for the random number generator to ensure reproducibility. Defaults to 42.
The generated weather data ranges are as follows:
- Temperature: Between -10°C and 40°C.
- Humidity: Between 20% and 100%.
- Wind Speed: Between 0 and 20 meters per second.
Returns:
- DataFrame: A pandas DataFrame with columns ['Date', 'Temperature', 'Humidity', 'Wind Speed'], containing the generated weather data for each day within the specified range.
- Axes: A matplotlib Axes object of the plot showing the generated weather data.
Raises:
- ValueError: If 'end_date' is before 'start_date', indicating an invalid date range.
Requirements:
- numpy
- pandas
- datetime
Example:
>>> start_date = datetime(2021, 1, 1)
>>> end_date = datetime(2021, 12, 31)
>>> data, plot = task_func(start_date, end_date)
>>> print(data.head()) # Display the first few rows of the DataFrame
Date Temperature Humidity Wind Speed
0 2021-01-01 8.727006 96.057145 14.639879
1 2021-01-02 19.932924 32.481491 3.119890
2 2021-01-03 -7.095819 89.294092 12.022300
3 2021-01-04 25.403629 21.646760 19.398197
4 2021-01-05 31.622132 36.987129 3.636499
>>> plot.get_figure().savefig("weather_data_plot.png") # Save the plot to a file
>>> os.remove("weather_data_plot.png")
"""
instruct prompt
Generate and plot weather data for a specified date range. This function creates a DataFrame containing simulated daily weather data within the specified date range. It generates random values for temperature, humidity, and wind speed for each day. The function also plots these parameters over the date range and returns both the DataFrame and the plot object. The generated weather data ranges are as follows: - Temperature: Between -10°C and 40°C. - Humidity: Between 20% and 100%. - Wind Speed: Between 0 and 20 meters per second.
The function should raise the exception for: ValueError: If 'end_date' is before 'start_date', indicating an invalid date range.
The function should output with:
DataFrame: A pandas DataFrame with columns ['Date', 'Temperature', 'Humidity', 'Wind Speed'], containing the generated weather data for each day within the specified range.
Axes: A matplotlib Axes object of the plot showing the generated weather data.
You should write self-contained code starting with:
Code
import numpy as np
import pandas as pd
from datetime import timedelta
def task_func(start_date, end_date, random_seed=42):
code prompt
Code
import numpy as np
import pandas as pd
from datetime import timedelta
def task_func(start_date, end_date, random_seed=42):
entry point
task_func
libs
- pandas
- datetime
- 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