Skip to main content

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

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)

👀 Learn More

📄 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

DataFrame


start

Start date of the requested period.

Data Type

datetime


end

End date of the requested period.

Data Type

datetime


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
AttributeDescriptionTypeDefault
squashSquash data from different sourcesboolTrue
fillFill missing recordsboolFalse
sourcesInclude source columns?boolFalse
locationAdd location-related columns (latitude, longitude, elevation)boolFalse
cleanRemove inaccurate databoolTrue
humanizeHumanize data values for wind direction and condition codeboolFalse
unitsUnit system for data values (e.g., metric or imperial)UnitSystemUnitSystem.METRIC
Return Value

DataFrame

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
AttributeDescriptionTypeDefault
parameterThe parameter which should be counted, if None the whole time series is consideredParameter or strNone
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
AttributeDescriptionTypeDefault
parameterThe parameter of interest, if None the whole time series is consideredParameter, str or NoneNone
Return Value

float

  • 0 means all data is missing
  • 1 means 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}%')