Historical UK air pollution data can be requested as .csv files from the DEFRA website. Recent data in JSON format, and historical data from Sept 2017,  is available through the air-aware API.

The following examples depend upon a small number of third-party libraries including pandas, matplotlib and requests. The Jupyter Notebook provides a convenient means for rendering charts on their own, for learning, and for experimenting with code. For more complex operations, such as making API calls and plotting live data with interactive charts, the Flask framework is recommended.  These are easy to install with plentiful information on their set up and use readily available.

Third-party libraries

Jupyter Notebook


Plotting JSON data using JavaScript libraries


Data Manipulation

Replace missing values using linear interpolation

Replace missing values using mean concentrations for a certain time interval

Reorganising data in a pandas Dataframe with NumPy arrays

Reshaping a pandas DataFrame from wide to long format

Obtaining statistical data for certain time intervals from time series data

Data Visualisation

Creating conditional plots using FacetGrid in Seaborn

Plotting categorical data using Seaborn’s box plot function

Plotting time series data using the Bokeh visualisation library

Plotting in Flask Applications