Visualization of Coronavirus(COVID-19) Confirm Cases in India on Map
Coronavirus: The first case of the COVID-19 pandemic in India was reported on 30 January 2020, beginning from China. The infection rate of COVID-19 in India is reported to be 1.7 percent, significantly lower than in the worst affected countries.
In this article, we will see the spread of covid19 cases in India concerning states/UTs.
This is a small project I have done using python and ML @jupyter notebook
Geopanadas: GeoPandas is an open-source project to make working with geospatial data in python easier.
BeautifulSoup: Extracting the data (Basically Html Files) of any website is called web scraping. This saves us a lot of time because we get a lot of data (a huge amount of data) in a structured form.
PRACTICAL IMPLEMENTATION
#Importing libraries
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import requests
from bs4 import BeautifulSoup
import geopandas as gpd
#this is just importing the required libraries which is required .
#reading Indian shapely file
data_map = gpd.read_file(‘Indian_States.shp’)
print(data_map.head())
#printing 25 number state
data_map[‘st_nm’].iloc[25]
st_nm geometry
0 Andaman & Nicobar Island MULTIPOLYGON (((93.71976 7.20707, 93.71909 7.2...
1 Arunanchal Pradesh POLYGON ((96.16261 29.38078, 96.16860 29.37432...
2 Assam MULTIPOLYGON (((89.74323 26.30362, 89.74290 26...
3 Bihar MULTIPOLYGON (((84.50720 24.26323, 84.50355 24...
4 Chandigarh POLYGON ((76.84147 30.75996, 76.83599 30.73623...
Out[31]:
'Punjab'
#Extracting data from Indian govt. site(web scrapping)
url = ‘https://www.mohfw.gov.in/'
#Request to extract data from site
web_content = requests.get(url).content
#applying html parser to parse html content
soup = BeautifulSoup(web_content, “html.parser”)
def extract_contents(row):
return [x.text.replace(‘\n’, ‘’) for x in row]
stats = []
all_rows = soup.find_all(‘tr’)
#print(all_rows)
for row in all_rows:
stat = extract_contents(row.find_all(‘td’))
if len(stat) == 6:
stats.append(stat)
#Converting html data into dataframe
new_cols = [“S. No.”, “Name of State / UT”,”Active Cases*”,”Cured/Discharged/Migrated*”,”Deaths**”,”Total Confirmed cases*”]
state_data = pd.DataFrame(data = stats, columns = new_cols)
state_data.head()

import matplotlib.pyplot as plt #matplotlib are used to deal with (graphs)
plt.figure(figsize=(28,15))
plt.barh(state_data[“Name of State / UT”],state_data[‘Active Cases*’],color=’red’)
plt.xticks(fontsize=25)
plt.yticks(fontsize=25)
plt.show()

#Correction required to match names in both datasets
data_map.rename(columns = {‘st_nm’:’Name of State / UT’}, inplace = True)
data_map[‘Name of State / UT’] =data_map[‘Name of State / UT’].str.replace(‘&’,’and’)
data_map[‘Name of State / UT’].iloc[0] = ‘Andaman and Nicobar Islands’
data_map[‘Name of State / UT’].iloc[1] = ‘Arunachal Pradesh’
data_map[‘Name of State / UT’].iloc[6] = ‘Dadar Nagar Haveli’
data_map[‘Name of State / UT’].iloc[23] = ‘Delhi’
data_map[‘Name of State / UT’].iloc[29]=’Telengana’
#Plotting map of The India
data_map.plot()

#Merging both datasets together
merged = pd.merge(data_map, state_data, on = ‘Name of State / UT’)
merged.drop(‘S. No.’, axis = 1, inplace = True)
merged.head()

#plotting coronavirus cases on map
fig, ax = plt.subplots(1, figsize=(20, 12))
ax.axis(‘off’)
#Set the title of the map
ax.set_title(‘Coronavirus Confirm cases in India’, fontsize=25)
merged.plot(column = ‘Active Cases*’,cmap=’plasma’,linewidth=0.8, ax=ax, edgecolor=’0.8',legend = True)
#Showing plot of India with coronavirus cases
plt.show()

GitHub link=> https://github.com/P-riyanka-prasad/Visualization-of-Coronavirus/blob/master/india.ipynb