Time Series

On this page

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:

Python
# 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)

🎯 Location Input#

Every time series function takes the location as its first argument: one or more weather stations, or geographical points.

Input Use it when
Station ID, or a list of IDs You know the stations' Meteostat IDs
Station object(s) You want to provide station metadata yourself, e.g. for stations not in the Meteostat database
DataFrame of stations You looked stations up first, e.g. with ms.stations.nearby (index named id)
Point object(s) You need data for a location rather than a station
Python
from datetime import datetime
import meteostat as ms

START = datetime(2024, 1, 1)
END = datetime(2024, 1, 31, 23, 59)

# Station ID(s)
ts = ms.hourly('10637', START, END)
ts = ms.hourly(['10637', '10635'], START, END)

# Station object with your own metadata
station = ms.Station(
    id='10637',
    name='Frankfurt Airport',
    country='DE',
    region='HE',
    lat=50.05,
    lon=8.6842,
    elevation=100
)
ts = ms.hourly(station, START, END)

# The four stations closest to a location
stations = ms.stations.nearby(ms.Point(50.1155, 8.6842, 113), limit=4)
ts = ms.hourly(stations, START, END)

# A geographical point (needs a provider that supports points)
point = ms.Point(50.05, 8.6842, 100)
ts = ms.hourly(point, START, END, providers=[ms.Provider.METNO_FORECAST])

🔀 Merging Time Series#

ms.merge combines several time series into one, for example data you fetched in separate requests. The time series must have the same granularity, and hourly time series the same time zone.

Python
from datetime import date
import meteostat as ms

# Two consecutive periods for New York LaGuardia Airport
ts1 = ms.daily('72503', date(2020, 1, 1), date(2020, 1, 10))
ts2 = ms.daily('72503', date(2020, 1, 11), date(2020, 1, 20))

ts = ms.merge([ts1, ts2])

# One DataFrame covering January 1–20
df = ts.fetch()
print(df)

👀 Learn More#

🔍 API#

meteostat.TimeSeries