COVID 19 Choropleth Maps

Choropleth Maps using Plotly to track COVID 19 cases.

Shraddha Anala
Towards Data Science

--

I’m expanding with more posts on ML concepts + tutorials over at my blog!

Photo by Ashkan Forouzani on Unsplash

Here’s a simple tutorial to plot Choropleth Maps using the Plotly graphing library in Python.

I was inspired by the WHO dashboard and wanted to implement one myself.

Turns out it’s pretty easy to do and although this article isn’t a part of my usual random dataset series, learning data visualization skills like this, are very important for a Data Scientist to communicate insights.

Let’s jump right into the tutorial.

1) Downloading & Cleaning the Dataset -

You can go ahead and download the dataset from the WHO site itself, but be warned there are a lot of special characters to be removed.

Additionally, some countries like Curacao, Saint Barthélemy, Reunion Islands etc., are improperly formatted. Therefore, there’s a ton of cleaning up to do before you can import the CSV file into a Pandas DataFrame.

You can skip the above hassle and download the dataset that I’ve already cleaned up, but this might mean that the data isn’t up-to-date at whatever time in the future you decide to implement this tutorial for yourself.

2) Importing the Cleaned Dataset -

Now that you’ve either cleaned the dataset yourself, or you’ve downloaded the preprocessed one, the next step is to import this dataset.

We will be dropping some columns that are not needed for plotting.

3) Choropleth Maps -

Plotting the Choropleth Maps is very easy with the Plotly graphing library.

We will have to create a data object which has the actual information about each country and their infection/death counts, and a layout object to view the plot.

There are 2 choropleth maps; one tracks the infection counts across the world and the other shows the number of COVID deaths.

COVID 19 Infections Count. GIF by author

Directly embedding interactive Plotly visualizations in Medium articles is no longer working, so I captured a gif of me hovering over the different countries to show you what the map looks like. You can view the interactive visualization by clicking on the link below.

And here’s how you can plot this map.

Once you execute the line, plot(fig_cases), the Choropleth Map will open up in your browser as an interactive map.

Following the same method for plotting death rates across the world.

COVID 19 Casualty Count. GIF by author.

Again, feel free to play around on this interactive visualization by clicking the link below.

There you go! Here’s how you can plot Choropleths Maps in a simple way. The main important point to keep in mind is setting up the dataset in a way that is easy to plot.

If you’ve implemented one yourself and want to figure out how to embed your interactive visualizations on Medium, you can check out this article.

Hope you found this tutorial useful and fun. You can take a look at my other articles for interesting Machine Learning tutorials and my GitHub repo.

Thank you very much for reading and I’ll see you soon!

--

--