Easy Way To Track Corona-Virus Statistics In Python

FeaImg COVID19Py

In this tutorial, we’re going to use the COVID19Py library to track Corona Virus Statistics in Python.

Good day, everyone! We are going through this difficult time, it only makes sense to do anything that we can to help people around us. As programmers, you can help spread information about the COVID virus, help people find places to get the vaccines, and much more.

It is a pre-built Corona Virus Stats tracker written in Python. All you have to do is install it, perform certain functions, and you’ll have access to information from all over the world. So let’s get started.

Setting Up COVID19Py

Python installation is as simple as it gets. Simply type the pip command into your command prompt.

pip install COVID19Py

Type the following command into your.py file to import this package:

import COVID19Py

This package has only one line of preprocessing, making it very simple to use.

covid19 = COVID19Py.COVID19()

Tracking COVID19 Information In Python

Now that we have a package object, we can begin using its methods.

Use the getLatest() function to gather the most up-to-date statistics on those impacted, those who have recovered, and the number of fatalities worldwide. It gives you a list of dictionaries.

L= covid19.getLatest()
{'confirmed': 277161199, 'deaths': 5377197, 'recovered': 0}

The getLocations() function is then used to filter through the massive amount of data gathered.

LS = covid19.getLocations()
{'id': 0, 'country': 'Afghanistan', 'country_code': 'AF', 'country_population': 37172386, 'province': '', 'last_updated': '2021-12-23T08:34:35.628637Z', 'coordinates': {'latitude': '33.93911', 'longitude': '67.709953'}, 'latest': {'confirmed': 157841, 'deaths': 7341, 'recovered': 0}}

The country code is required to look through the data for a certain nation. So here’s an easy method to acquire all of the country codes included in the bundle.

C= {}
for i in locations:
    C[i.get('country')] = i.get('country_code')

Simply enter this piece of code to obtain the statistics for India.

code = C.get('India')
india = covid19.getLocationByCountryCode("IN")
for i in india:
{'confirmed': 34765976, 'deaths': 478759, 'recovered': 0}


Now that you have all of the tools at your disposal, find all of the data you want so that you may compare and contrast other nations’ statistics.

You can also use the Google Trends API to see the trend of the Corona Virus throughout the internet.

Liked the tutorial? In any case, I would recommend you to have a look at the tutorials mentioned below:

  1. Python statistics module – 7 functions to know!
  2. How to Calculate Summary Statistics in Python?
  3. Data Analytics vs. Data Science

Thank you for taking your time out! Hope you learned something new!! 😄