# 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 {#example}

::::::tabs
:::::tab{label="Hourly" value="hourly" default}

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)
```

:::::
:::::tab{label="Daily" value="daily"}

Let's fetch some daily temperature data for Frankfurt, Germany in 2018:

```python
# 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)
```

:::::
:::::tab{label="Monthly" value="monthly"}

Let's fetch some monthly data for Frankfurt, Germany from 2000 to 2018:

```python
# 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)
```

:::::
::::::

## 🎯 Location Input {#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`](../api/meteostat.Station.md) 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`](../api/meteostat.stations.nearby.md) (index named `id`) |
| [`Point`](../api/meteostat.Point.md) 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])
```

:::tip[Faster requests]
With the default providers, `ms.Station(id='10637')` (just the ID) is enough. It skips the metadata lookup.
:::

:::warning[Points need point providers]
Only providers that support geographical points work with a `Point`. For historical observations at a location,
fetch nearby stations and [interpolate](../interpolation.md) them to the point.
:::

## 🔀 Merging Time Series {#merging}

[`ms.merge`](../api/meteostat.merge.md) 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))

# highlight-next-line
ts = ms.merge([ts1, ts2])

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

## 👀 Learn More {#learn-more}

::doc-cards

## 🔍 API {#api}

[`meteostat.TimeSeries`](../api/meteostat.TimeSeries.md)
