The Quick Python Book, Third Edition cover
Welcome to liveBook!

This is an online version of the Manning book The Quick Python Book, 3rd. With liveBook you can access Manning books in-browser — anytime, anywhere.

Case study

In this case study, you walk through using Python to fetch some data, clean it, and then graph it. This project may be a short one, but it combines several features of the language I’ve discussed, and it gives you a chance to a see a project worked through from beginning to end. At almost every step, I briefly call out alternatives and enhancements that you can make.

Global temperature change is the topic of much discussion, but those discussions are based on a global scale. Suppose that you want to know what the temperatures have been doing near where you are. One way of finding out is to get historical data for your location, process that data, and plot it to see exactly what’s been happening.

Getting the case study code

The following case study was done by using a Jupyter notebook, as explained in chapter 24. If you’re using Jupyter, you can find the notebook I used (with this text and code) in the source code downloads as Case Study.ipynb. You can also execute the code in a standard Python shell, and a version that supports that shell is in the source code as Case Study.py.

Fortunately, several sources of historical weather data are freely available. I’m going to walk you through using data from the Global Historical Climatology Network, which has data from around the world. You may find other sources, which may have different data formats, but the steps and the processes I discuss here should be generally applicable to any data set.

Downloading the data

Parsing the inventory data

Selecting a station based on latitude and longitude

Selecting a station and getting the station metadata

Fetching and parsing the actual weather data

Fetching the data

Parsing the weather data

Saving the weather data in a database (optional)

Selecting and graphing data

Using pandas to graph your data

sitemap