Coders Packet

Python code to visualize COVID 19 data in a Bubble map

By Kiran Reddy

In this project, we are going to learn how to 1) Web scrape COVID 19 data of India 2) Visualize it in a Bubble Map

import pandas as pd

#for getting India map
import folium

coordinates = pd.read_csv("latandlon.csv")
# Retreving the LIVE COVID19 Stats from Wikipedia
coronastats = pd.read_html('https://en.wikipedia.org/wiki/COVID-19_pandemic_in_India#covid19-container',match='State/Union Territory')

#Convert to DataFrame
covid19 = pd.DataFrame(coronastats[0])

#covid19.head()
covid19
# cleaning Covid19 Dataframe

# Removing unnecessary rows at the tail and Unnecessary columns
covid19 = covid19.iloc[:-2,:-4]

# Renaming Attribute Names for simplicity
covid19.columns = ['State','Total cases','Deaths','Recoveries','Active cases']

#covid19.head()
covid19
covid19['Recoveries']=covid19.Recoveries.astype(float)
covid = covid19.join(coordinates.set_index('State'), on = 'State')

#final_data = final_data['State']

#df.join(other.set_index('key'), on='key')
covid
# Make an empty map
m1 = folium.Map(location=[20.5937,78.9629], zoom_start=5)
state = list(covid['State'])
latitude = list(covid['Latitude'])
longitude = list(covid['Longitude'])
total = list(covid['Total cases'])
deaths = list(covid['Deaths'])
recovery = list(covid['Recoveries'])
active = list(covid['Active cases'])

for s, lat, long, t, d, r, a in zip(state,latitude ,longitude ,total , deaths, recovery, active): folium.Circle( location=[lat, long], popup=folium.Popup(('State : ' + s + '
' + 'Total Cases : ' + str(t) + '
' + 'Deaths : ' + str(d) + '
' + 'Recoveries : ' + str(r) + '
' + 'Active Cases : ' + str(a) + ''), max_width=200), radius=r * 0.2, color='green', fill=True, fill_color='green' ).add_to(m1) # Save it as html # m.save('mymap.html') m1

 

Download Complete Code

Comments

No comments yet