Analyze Historical Weather Data with Python

Update: We’ve published a first stable version of the Meteostat Python library. Please read this article for more information.

Just one week after the release of our open weather station directory, we are now launching an official Meteostat Python library. The library will co-exist with our JSON API and provides a more flexible interface which targets the data science community. It’s build on top of the Meteostat bulk data interface and utilizes Pandas for data analysis. We invite everyone to test the 0.1.0 version of the Meteostat Python library. If that sounds interesting to you, keep reading this article and learn how to get started.

Image for post
Image for post


The Meteostat Python package is available through PyPI. Therefore, installing the library is as easy as running this command:

The library depends on Pandas and PyArrow. PIP will install all dependencies automatically for you. Once the package is installed you can start analysing. Thanks to Cloudflare’s CDN, Meteostat data dumps can be accessed relatively fast from anywhere. That’s why you don’t even need an API key or any other form of authentication. In fact, you can access weather and climate data without any limits from our side. However, keep in mind that the library will cache data dumps on your local drive. If you are short in storage, consider keeping an eye on the size of your cache. By default, files will be stored in the ~/.meteostat/cache directory. If you want to keep these files somewhere else, just specify the cache_dir parameter when calling any of the library’s classes.

Example: 2018 Temperature Data for Vancouver

Enough of the preparation, let’s dive into the data. In this example we will utilize the Stations and Daily classes of the library to create a chart which visualizes the 2018 daily temperatures in Vancouver, BC. This use case is similar to the ones covered by our JSON API and is a very common task when working with weather and climate data. We do know a geographic location we want to analyze data for, but have no idea about the weather stations nearby.

Let’s import some classes & functions, first:

Now we can fetch a weather station which is located close to our point of interest. Simply pass a latitude and longitude to the nearby method:

In this block we’re also specifying a daily parameter. By doing so we are making sure, that the weather station did actually provide daily statistics in 2018. It’s not required but really makes sense it this case. After calling fetch() the station variable holds a Pandas DataFrame which contains meta information about the weather station we’ve selected. This DataFrame can be passed on to the Daily class for access to the actual weather data:

data is now a Pandas DataFrame which contains one row per day (exception: time series might contain gaps). From now on, we can use Pandas methods on our DataFrame. In this example we will visualize the average, minimum and maximum temperatures in a line chart:

The chart should look like that:

Image for post
Image for post

You can view the full Gist here.

The library is currently limited to the scientific units listed in the documentation. The roadmap for our version 1.0 release includes extended unit and time zone support.

We will share further examples in the upcoming weeks. For now we want to invite you to install the library and try it out. I bet there are still tons of bugs and things to improve. If you want to get involved, just jump over to GitHub and help us building an open interface for historical weather data.

If you don’t want to miss out on the latest news and updates from Meteostat, follow us on Twitter and join our Slack channel.

Thanks for reading!


A free online service which provides weather and climate…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store