Visualizing COVID-19 Data Beautifully in Python (In 5 Minutes or Less!!) - by Nik Piepenbreier - Towards Data Science
Visualizing COVID-19 Data Beautifully in Python (In 5 Minutes or Less!!) - by Nik Piepenbreier - Towards Data Science
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 1 of 8
Visualizing COVID-19 Data Beautifully in Python (in 5 Minutes or Less!!) | by Nik Piepenbreier | Towards Data Science 7/11/20, 09:51
Let’s create some beautiful data visualizations in Python! Source: Nik Piepenbreier.
Matplotlib may be the de facto data visualization library for Python, but it’s
not always the prettiest. In this post, we’ll explore how to turn a drab,
default Matplotlib graph into a beautiful data visualization. We’ll explore
COVID-19 data to see how the virus has spread throughout diGerent
countries.
Loading in our data and creating summary variables. Source: Nik Piepenbreier
only the countries in our list countries . Selecting the data makes the
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 2 of 8
Visualizing COVID-19 Data Beautifully in Python (in 5 Minutes or Less!!) | by Nik Piepenbreier | Towards Data Science 7/11/20, 09:51
with the number of cases as the data Nelds. This new dataframe is called
covid . We then set the index of the dataframe to be the date and assign the
dictionary that is storing all our countries’ populations and divide each
value by the population and multiply it by 100,000 to generate a number of
cases per 100,000 people.
If you ever want to learn how to unpivot data, check out this tutorial on the
melt function available in Pandas.
Let’s take a look at how our data has transformed from beginning up until
now:
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 3 of 8
Visualizing COVID-19 Data Beautifully in Python (in 5 Minutes or Less!!) | by Nik Piepenbreier | Towards Data Science 7/11/20, 09:51
How we’ve reshaped our data to tell a story. Source: Nik Piepenbreier
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 4 of 8
Visualizing COVID-19 Data Beautifully in Python (in 5 Minutes or Less!!) | by Nik Piepenbreier | Towards Data Science 7/11/20, 09:51
Then, in Section 8, we create a for-loop that generates label text for the
various countries. This for-loop gets each country’s name from the keys in
the dictionary in the form of a list and iterates over this list. It places text
containing the country’s name to the right of the last x-value
( covid.index[-1] → the last date in the dataframe), at the current day’s y-
value (which will always be equal to the max value of that column).
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 5 of 8
Visualizing COVID-19 Data Beautifully in Python (in 5 Minutes or Less!!) | by Nik Piepenbreier | Towards Data Science 7/11/20, 09:51
Our First Visualization — Cases over Time by Country. Source: Nik Piepenbreier
Creating our second visualization — cases per 100,000 people. Source: Nik Piepenbreier
This section follows mostly what we did for our Nrst graph. This goes to
show how simple it is to update visualizations for diGerent datasets once
you’ve set up a chart using Python!
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 6 of 8
Visualizing COVID-19 Data Beautifully in Python (in 5 Minutes or Less!!) | by Nik Piepenbreier | Towards Data Science 7/11/20, 09:51
Our Second Visualization — Cases per 100,000 people per country. Source: Nik Piepenbreier
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 7 of 8
Visualizing COVID-19 Data Beautifully in Python (in 5 Minutes or Less!!) | by Nik Piepenbreier | Towards Data Science 7/11/20, 09:51
https://towardsdatascience.com/visualizing-covid-19-data-beautifully-in-python-in-5-minutes-or-less-affc361b2c6a Page 8 of 8