hourly_weather_data.csv
file.
import requests
import pandas as pd
# Replace with your desired parameters
latitude = 52.52 # Example: Berlin
longitude = 13.405
start_date = '2023-01-01'
end_date = '2023-01-31'
hourly_vars = [
'temperature_2m', 'relative_humidity_2m', 'rain', 'snowfall',
'snow_depth', 'surface_pressure', 'cloud_cover', 'wind_speed_10m',
'wind_direction_10m', 'wind_gusts_10m'
]
url = 'https://api.open-meteo.com/v1/forecast'
params = {
'latitude': latitude,
'longitude': longitude,
'start_date': start_date,
'end_date': end_date,
'hourly': ','.join(hourly_vars),
'timezone': 'UTC'
}
response = requests.get(url, params=params)
data = response.json()
# Convert to DataFrame
df = pd.DataFrame(data['hourly'])
df['date'] = pd.to_datetime(df['time'])
# Reorder columns
cols = ['date'] + [var for var in hourly_vars]
df = df[cols]
# Save to CSV
df.to_csv('hourly_weather_data.csv', index=False)
print('CSV file generated successfully.')
Some data is missing and could not be displayed.