Corona Virus Live Updates for India – Using Python
As we know the whole world is being affected by COVID-19 pandemic and almost everyone is working from home. We all should utilize this duration at best, to improve our technical skills or writing some good Pythonic scripts.
Let’s see a simple Python script to demonstrate the state-wise corona virus cases in India. This Python script fetches the live data from Ministry of Health Affairs Official Website. Then data is represented in the horizontal bar graph.
To run this script follow the below installation –
$ pip install bs4 $ pip install tabulate $ pip install matplotlib $ pip install numpy
Let’s try to execute the script step-by-step.
Step #1:
# importing libraries import requests from bs4 import BeautifulSoup from tabulate import tabulate import os import numpy as np import matplotlib.pyplot as plt |
Step #2:
extract_contents = lambda row: [x.text.replace('\n', '') for x in row] SHORT_HEADERS = ['SNo', 'State','Indian-Confirmed', 'Foreign-Confirmed','Cured','Death'] response = requests.get(URL).content soup = BeautifulSoup(response, 'html.parser') header = extract_contents(soup.tr.find_all('th')) stats = [] all_rows = soup.find_all('tr') for row in all_rows: stat = extract_contents(row.find_all('td')) if stat: if len(stat) == 5: # last row stat = ['', *stat] stats.append(stat) elif len(stat) == 6: stats.append(stat) stats[-1][1] = "Total Cases" stats.remove(stats[-1]) |
Step #3:
objects = [] for row in stats : objects.append(row[1]) y_pos = np.arange(len(objects)) performance = [] for row in stats : performance.append(int(row[2]) + int(row[3])) table = tabulate(stats, headers=SHORT_HEADERS) print(table) |
Output:

Step #4:
plt.barh(y_pos, performance, align='center', alpha=0.5, color=(234/256.0, 128/256.0, 252/256.0), edgecolor=(106/256.0, 27/256.0, 154/256.0)) plt.yticks(y_pos, objects) plt.xlim(1,80) plt.xlabel('Number of Cases') plt.title('Corona Virus Cases') plt.show() |
Output:

Recommended Posts:
- Corona Virus Details in India - Using Python PyQt5
- Corona Virus cases of various countries - Using Python PyQt
- Get Corona cases details - Python PyQt5
- Python - Get Confirmed, Recovered, Deaths cases of Corona around the globe
- Python | Find Live running status and PNR of any train using Railway API
- Send SMS updates to mobile phone using python
- Computer Vision module application for finding a target in a live camera
- Python - Read blob object in python using wand library
- Python | PRAW - Python Reddit API Wrapper
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- Important differences between Python 2.x and Python 3.x with examples
- MySQL-Connector-Python module in Python
- Python | Merge Python key values to list
- Python | Index of Non-Zero elements in Python list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

