The world’s leading publication for data science, AI, and ML professionals.

Data visualization: How NAFTA countries are doing in the pandemic

Time at home during the pandemic

Time at home and total cases during the pandemic

Photo by Bonnie Kittle on Unsplash
Photo by Bonnie Kittle on Unsplash

Introduction

The North American Free Trade Agreement (NAFTA) is an economic bloc made up of the United States, Canada, and Mexico. Effectively created on January 1, 1994, it aims to strengthen trade relations between these countries. One of its objectives is to compete for head-on against the European and Chinese markets, which have evolved vigorously in recent years.

The NAFTA block is essentially economic, there is no institution or government to manage the block compared to other economic blocks. As the bloc is known for its social and economic disparity, it is interesting to analyze its graphs of social isolation and the total cases of Covid19 during the pandemic to get a better idea of ​​each country and their differences in this new scenario.


Database

All data was taken from the google mobility report website, There you will be able to see community mobility reports about what has changed due to the policies created to face Covid-19. They show graphs with trends of displacement over time by region and in different categories. Finally, data on the total number of cases were removed from the site Our World in Data.


Pre-processing and cleaning

Important libraries for the program

import Pandas as pd
import matplotlib.pyplot as plt

Reading the data

link='https://www.gstatic.com/covid19/mobility/Global_Mobility_Report.csv'
data = pd.read_csv(link)
data.head()
There are too many columns
There are too many columns

Separating the main columns

data_country = data.iloc[:,[1,7,8,9,10,11,12,13]].copy()
data_country.columns = ['country','date', 'retail', 'grocery', 'parks', 'transit', 'workplaces', 'residential']
data_country.date = pd.to_datetime(data_country.date)
data_country.index = data_country.date
data_country.drop(labels = 'date', axis=1, inplace=True)
data_country.head()
All countries
All countries

Grouping the countries of the economic bloc about the "residential" column, using the method "groupby".

data_country.groupby(by[data_country.index,"country"])
.mean().unstack()["residential"][['United States','Canada','Mexico']]
NAFTA countries only
NAFTA countries only

Data visualization

fig, ax = plt.subplots(nrows=1,ncols=3,figsize=(20,4))
item = "residential" #grocery, parks, transit, workplaces, retailcountrys = ['United States','Canada','Mexico']
for i,country in enumerate(countrys):
data_country.groupby(by=[data_country.index,"country"]).mean().unstack()[item].rolling(window=7).mean().plot(legend=False,color="grey",linewidth=1, alpha=0.4, ax=ax[i])
data_country.groupby(by=[data_country.index,"country"]).mean().unstack()[item][country].rolling(window=7).mean().plot(legend=False,color="blue",linewidth=7, alpha=0.6, ax=ax[i])
ax[i].set_title(country,fontsize=12,ha='right')
ax[i].xaxis.grid(False)
ax[i].set_xlabel("")
ax[i].set_xticklabels(["","Mar","Apr","May","Jun","Jul","Aug","Sep"])
ax[i].xaxis.set_tick_params(labelsize=12)
ax[i].yaxis.set_tick_params(labelsize=12)
if (i==0) or (i==2):
ax[i].yaxis.tick_right()
else:
ax[i].set_yticklabels([])
#plt.savefig("nafta.png",dpi=300)
plt.show()
Graph of social isolation throughout the pandemic
Graph of social isolation throughout the pandemic

In this graph, we have the value of the country highlighted by the color blue and gray we have the values ​​of other countries in the world.

graph of the total number of cases for each country in relation to the world
graph of the total number of cases for each country in relation to the world

In this second graph we can see that even though the United States had an index and tended to have similar case numbers to Canada, Covid’s number of cases is numerous times greater than that of Canada and Mexico, revealing to us that the virus has not yet been controlled compared to Canada which has a similar graph for isolation.


Conclusion

It is important to note that the two graphs are different, Canada, for example, had a high level of social isolation like Mexico, and today it already has a much lower number, this may say that there was greater control by the government and the disease population. So, even though the USA and Canada have a similar graph of social isolation, the graph for the number of cases shows us a very large disparity for the USA, having very high-value participation in all countries of the bloc.


For a better understanding of the code and data observed here is the link to the repository on GitHub and for more in-depth NAFTA content.


Related Articles