Recreating the Financial Times’ Economic Recovery Graph With Google Mobility Data
By: Thiago Rodrigues
Tags: Pandas, Python, Covid 19, Data Science, Data Visualization

At this point, I think it’s safe to say we’ve all seen more than our fair share of news about COVID-19, as well as graphs that show how the number of cases has been increasing or decreasing in recent times. The latter provides us with tools to see for ourselves how the situation has been evolving since the start of the year and to make estimates as to when it will end.

But there’s another type of graph that should be getting just as much attention. That type consisting of graphs that present how society is reacting to the pandemic. After all, even if cases go down, things won’t be back to normal until the economy is back up and people are circulating as they did before. That’s where posts such as The Financial Times’ “Pandemic crisis: Global economic recovery tracker” come into action. They give us an early picture of how close or far away we are from the world pre-crisis.

Photo by Julian Wan on Unsplash

In this post, we’ll dive into how to make a graph that reflects society’s current state using the data from Google’s COVID-19 Community Mobility Reports and taking inspiration from the Leisure graph from the financial times’ post.

We’ll be using Python along with pandas to process the data and Matplotlib to visualize it. The code will be available in Google Colab and the result should look something like this:

Plots for 6 different countries displaying how much people have been staying home. (the value 0 references the pre-crisis state)

Plots for 6 different countries displaying how much people have been frequenting their workplaces.

After downloading the .csv file or using the link directly, we read it using panda’s built-in read_csv() function and begin our work.

A basic look at the data frame using the pandas df.info() method.

The dataset contains a column for countries and 2 for sub-regions, which can vary depending on the country since different countries decide to organize their territories differently.

For our purposes, we’ll be dropping the sub-regions columns but you can choose to keep them if you want to do a more in-depth analysis for any country of your choice. To do that, we’ll save a copy of the data frame into a different variable, keeping only what we want. I’ll also be dropping the metro_area and iso_3166_2_code columns since they’re also not of use for what we want.

df_countries = df.loc[df.sub_region_1.isnull(), :].iloc[:, [1, 7, 8, 9, 10, 11, 12, 13]].copy()

After filtering what we want to keep from what we can throw away, we still need to do a few things to be able to work with this data.

First, we’ll change the dates, which are currently stored as strings, into the DateTime data type, which will allow us to manipulate them better, perform operations, and all that fancy stuff. Then, we’ll set them as the new index for our data frame since it’s way easier to sort by dates than it is by your standard sequence of integers.

df_countries.date = pd.to_datetime(df_countries.date)

df_countries.index = df_countries.date

df_countries.drop(labels='date', axis=1, inplace=True

And finally, we’ll change the column names so they’re easier to work with.