COVID -19 Data visualization

Nischal Madiraju
3 min readApr 12, 2020

--

In continuation of my previous article…here are some ways you can visualize the data fetched from the API to build your own dashboard:

Note:- I have used the Coronavirus COVID19 API (covid19api.com) that I discussed in my previous article, which you can find here:

https://medium.com/@nischalmadiraju/covid-data-apis-for-predictive-analytics-c12376661618

Or if you want to directly look into the API you can go to the following link:

https://documenter.getpostman.com/view/10808728/SzS8rjbc?version=latest

  1. To begin with, I am going to import the required library:

Requests: The requests module allows you to send HTTP requests using Python. The HTTP request returns a Response Object with all the response data (content, encoding, status, etc.).

Pandas: Pandas is the most popular Python library that is used for data analysis. It provides highly optimized performance with back-end source code is purely written in Python.

2. Now we have to get data from the API:

Here we are using the request.get method to fetch the data from the API.

3. Now that we have our data let us first put it in a dataframe to get a neat tabular representation and then we will use the dataframe for plotting the graphs accordingly.

Here we have used pd.DataFrame.from_dict(x[‘Countries’]) to save the country-specific data from the response in the variable df

4. Now to plot the data first, I grouped the data by country using ‘df.groupby(“Country”).mean()’ which was saved in ‘country_wise_grouped’ variable, then I sorted the grouped data the ‘TotalConfirmed’ column and then used ‘[:10]’ to display the first 10 elements in the graph. The “.plot()” method with the parameter ‘kind’ set to ‘bar’ was used to plot the data in the graph.

5. If you want to only display specific columns of data in the bar chart then you can set the ‘y’ parameter accordingly in the ‘.plot()’ method. For example, if you want to only display ‘TotalRecovered’ and ‘NewConfirmed’ you would send the parameters like this:

You will be able to find this code here:

Feel free to update it and also let me know in the comments if you would like me to cover anything else.

--

--

Nischal Madiraju
Nischal Madiraju

Written by Nischal Madiraju

Writes about Artificial intelligence, Machine Learning and Deep Learning. Pursuing Msc in Artificial Intelligence at the University of Groningnen

No responses yet