Time Series
Meteostat provides access to time series data for thousands of weather stations worldwide. These time series are provided in different granularities and can be consumed through a single interface.
🚀 Example
- Hourly
- Daily
- Monthly
Let's fetch some hourly data for Atlanta, USA from January 1 to December 31, 2018:
# Import Meteostat library and dependencies
from datetime import datetime
import meteostat as ms
# Set time period
start = datetime(2018, 1, 1)
end = datetime(2018, 12, 31, 23, 59)
# Get hourly data
ts = ms.hourly(ms.Station(id='72219'), start, end)
df = ts.fetch()
# Print DataFrame
print(df)
Let's fetch some daily temperature data for Frankfurt, Germany in 2018:
# Import Meteostat library and dependencies
from datetime import date
import meteostat as ms
# Set time period
start = date(2018, 1, 1)
end = date(2018, 12, 31)
# Get daily data
ts = ms.daily(ms.Station(id='10637'), start, end)
df = ts.fetch()
# Print DataFrame
print(df)
Let's fetch some monthly data for Frankfurt, Germany from 2000 to 2018:
# Import Meteostat library and dependencies
from datetime import date
import meteostat as ms
# Set time period
start = date(2000, 1, 1)
end = date(2018, 12, 31)
# Get monthly data
ts = ms.monthly(ms.Station(id='10637'), start, end)
df = ts.fetch()
# Print DataFrame
print(df)
👀 Learn More
📄️ Hourly Weather
If you want to investigate the weather on a particular day or a short period of time, hourly time series data is a great choice.
📄️ Daily Weather
Daily time series data is ideal for analyzing weather patterns over longer periods, such as weeks, months, or years.
📄️ Monthly Weather
Monthly time series data is perfect for examining long-term climate trends and seasonal patterns over extended periods, such as years or decades.
📄 Source Code
The source code of the TimeSeries class is available on GitHub.
🔍 API
Interface
Through one of the following:
Parameters
Please refer to the respective interface documentation for a list of accepted parameters.
Properties
granularity
The time series's granularity.
Data Type
Granularity
stations
Included weather stations.
Data Type
start
Start date of the requested period.
Data Type
end
End date of the requested period.
Data Type
timezone
Time zone of the period and records (only hourly granularity).
Data Type
str
parameters
Included meteorological parameters.
Data Type
List[Parameter]
freq
The time series's frequency (e.g. 1h in case of hourly granularity).
Data Type
str
empty
Is the time series empty?
Data Type
bool
providers
Included data providers.
Data Type
List[Provider]
licenses
Applicable licenses.
Data Type
List[License]
attribution
The attribution/copyright string.
Data Type
str
commercial
Can data be used for commercial purposes?
Data Type
bool
valid
Does the time series pass all quality checks?
Data Type
bool
lapse_rate
The temperature's lapse rate, if applicable (at least two included weather stations with sufficient data).
Data Type
float or None
Methods
validate
Check if the time series passes all quality checks.
Attributes
This method does not accept any attributes.
Return Value
bool
Example
from datetime import date
import meteostat as ms
# Specify time range
START = date(2018, 1, 1)
END = date(2018, 12, 31)
# Get daily data
ts = ms.daily('10637', START, END)
is_valid = ts.validate()
print(f'Time series valid: {is_valid}')
fetch
Fetch the actual weather/climate data.
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
squash | Squash data from different sources | bool | True |
fill | Fill missing records | bool | False |
sources | Include source columns? | bool | False |
location | Add location-related columns (latitude, longitude, elevation) | bool | False |
clean | Remove inaccurate data | bool | True |
humanize | Humanize data values for wind direction and condition code | bool | False |
units | Unit system for data values (e.g., metric or imperial) | UnitSystem | UnitSystem.METRIC |
Return Value
Example
from datetime import date
import meteostat as ms
# Specify time range
START = date(2018, 1, 1)
END = date(2018, 12, 31)
# Get daily data
ts = ms.daily('10637', START, END)
df = ts.fetch()
# Print the DataFrame
print(df)
count
Get the number of rows in the whole time series or by parameter. NaN values are excluded.
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
parameter | The parameter which should be counted, if None the whole time series is considered | Parameter or str | None |
Return Value
int
Example
from datetime import date
import meteostat as ms
# Specify time range
START = date(2018, 1, 1)
END = date(2018, 12, 31)
# Get daily data
ts = ms.daily('10637', START, END)
count = ts.count(ms.Parameter.PRCP)
# Print the DataFrame
print(f'{count} rows with precipitation data')
completeness
The share of non-NaN values of the time series's full length.
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
parameter | The parameter of interest, if None the whole time series is considered | Parameter, str or None | None |
Return Value
float
0means all data is missing1means all data is available
Example
from datetime import date
import meteostat as ms
# Specify time range
START = date(2018, 1, 1)
END = date(2018, 12, 31)
# Get daily data
ts = ms.daily('10637', START, END)
completeness = ts.completeness(ms.Parameter.PRCP)
# Print the DataFrame
print(f'Precipitation data completeness: {completeness * 100}%')