Can Google’s Mobility Report explain New Zealand’s win against the virus? | by Alejandra Vlerick | Towards Data Science

Europe has slowly started opening up after months of restless lockdown, this gives me hope that the worst is behind us. Working from home and virtual wine evenings with friends have become the new ‘normal’. These measures have been put into motion to enforce physical distancing and ultimately slow down the spread of the deadly virus.
How effective have these policies been in reducing human movement? What impact has it had on the way people live, work and move?
Google introduced the COVID-19 Community Mobility Reports using anonymous data gathered from apps such as Google Maps. This dataset is regularly updated by Google itself and can be found here. The latest date available for the purpose of this analysis is May 24th.
Specific categories of destinations have been identified in this Google study and they have measured the number of visitors to those destinations. The number of visits per day are then compared to a baseline day (selected to be an average day before the pandemic).
Grocery stores
Pharmacies
Time spent at home
A baseline day is a ‘normal day’ (not a holiday, sports event, Valentine’s, St. Patrick’s, etc). The baseline day provides a reliable objective value for a specific day of the week. Meaning that we have a baseline value of people going to the groceries store on Monday, Tuesday, Wednesday, Friday, Saturday and Sunday.
Creating baseline days is a clever way of differentiating weekend from weekdays for example. I usually do my grocery shopping on weekends, not Tuesdays. I suspect I’m not alone in this.
In Spain, France or Belgium, supermarkets are not open on Sundays, the baseline value will be lower than for countries where everything is always open.
The data is presented in percentage change, this can be positive (when mobility to a destination increased) or negative (when it decreased).
A choropleth map is a thematic map in which areas are shaded in proportion to a statistical variable that represents an aggregate summary of a geographic characteristic within each area.
Additionally, I chose to use a line-graph to plot the mobility change in four countries that have been particularly affected by the virus: United States, Brazil and the United Kingdom. I also added New Zealand because they recently eradicated their last case of coronavirus. Impressive!
Retail and recreation: How did the number of visitors to retailers and recreation centres change since the beginning of the pandemic?
The graph below paints an image of the percentage change in mobility when compared with the baseline value.
A few observations can be made:
March 15th was the first day where more coronavirus cases were recorded outside of mainland China than inside. This triggered the change in mobility pattern for all the countries presented in this study.
The country with the most noticeable change in mobility compared to baseline values was New Zealand. They reduced their store visits by 90%! More than any other country.
It is important to notice that the United States as an increasing trend in the number of store visits that started from April 12 onwards.
After a drastic change in behaviour that reached a peak on March 29th, American’s have allowed themselves to visit more and more retail stores. In comparison, the United Kingdom saw a constant decrease in store visits that hit a minimum on March 29th, but this number of store visits has managed to stay constant throughout the isolation period.
The number of visits made to pharmacies compared to the baseline varies greatly by country, as can be seen from the graph below. For the United States, the change in number of visits transitioned from positive to negative on the 22nd of March. On this day, the number of coronavirus cases was 26,747, overtaking countries like Spain, Iran and Germany. This made them the third-highest affected country in the world.
New Zealand is again at the top of the chart with the highest percentage change, meaning they made the least pharmacy visits.
Note: Unlike the previous two charts, the percentages here are positive and they indicate in increase in time spent at home (previously we were talking about a decrease in visits to stores or pharmacy) .
A couple of observations can be made:
The United States was the first to enforce stay at home policies, but this translated into only 15 -20% more time spent at home than on baseline days. During April and May, this percentage decreased to 5 -15%. This is in line with the previous observations as the number of store visits and pharmacy visits increased during this period.
It is surprising to note that the United States behaviour is very similar to that in Brazil.
New-Zealand was the last to impose stay at home policies, yet they had the biggest percentage change reaching on average 35% more time spent at home. This value stayed constant until early May when the government allowed more freedom of movement.
Many more insights can be drawn from the information provided by Google’s Mobility report. This article is just an initial appraisal. More updates will come soon, please comment below of you would like to see your country of origin or residence in the updates to come.
# Import librariesimport numpy as npimport pandas as pdimport plotly as pyimport plotly.express as pximport plotly.graph_objs as gofrom plotly.subplots import make_subplotsfrom tabulate import tabulate# Read Datadf = pd.read_csv("data/Global_Mobility_Report.csv", low_memory=False)# Rename columnsdf = df.rename(columns={'country_region':'Country'})df = df.rename(columns={'date':'Date'})df = df.rename(columns={'retail_and_recreation_percent_change_from_baseline':'retail'})df = df.rename(columns={'grocery_and_pharmacy_percent_change_from_baseline':'pharmacy'})df = df.rename(columns={'parks_percent_change_from_baseline':'parks'})df = df.rename(columns={'transit_stations_percent_change_from_baseline':'transit_station'})df = df.rename(columns={'workplaces_percent_change_from_baseline':'workplaces'})df = df.rename(columns={'residential_percent_change_from_baseline':'residential'})df.drop(['country_region_code','sub_region_1', 'sub_region_2'], axis=1, inplace = True)print(tabulate(df[20000:20050], headers='keys', tablefmt='psql'))# Manipulate Dataframedf_countries = df.groupby(['Country', 'Date']).sum().reset_index().sort_values('Date', ascending=False)df_countries = df_countries.drop_duplicates(subset = ['Country'])# Manipulating the original dataframedf_countrydate = dfdf_countrydate = df_countrydate.groupby(['Date','Country']).sum().reset_index()min_cases = df_countrydate['residential'].min()df_country = df.groupby(['Country','Date']).sum().reset_index()c2 = df_country[df_country['Country']=="New Zealand"]c3 = df_country[df_country['Country']=="Brazil"]c4 = df_country[df_country['Country']=="United Kingdom"]c5 = df_country[df_country['Country']=="United States"]frames = [c2, c3, c4, c5]countries = pd.concat(frames)fig = px.line(countries, x="Date", y="pharmacy", title='pharmacy', color = 'Country')# fig.show()fig = px.choropleth(df_countrydate,                    locations="Country",                    locationmode="country names",                    color="retail",                    hover_name="Country",                    animation_frame="Date",                    # range_color=(0, 20000),                    range_color=(-500, 500),                    color_continuous_scale=px.colors.diverging.Picnic,                    color_continuous_midpoint=min_cases,                    )fig.update_layout(    title_text='Stay at home (quarantine) during coronavirus pandemic',    title_x=0.5,    geo=dict(        showframe=False,        showcoastlines=False,    ))# fig.show()
All the code can be found in the world_covid.py file on Github here!
If you like my work, I’d greatly appreciate if you followed me Medium here.
If you have any questions, suggestions or ideas on how to improve, please leave a comment below or get in touch through LinkedIn here.