Nandita S — Published On May 26, 2021
Beginner Data Visualization Python

This article was published as a part of the Data Science Blogathon


This blog is aimed to show the Covid cases prevailing in the Indian States. We have been going through this pandemic for over a year now. The numbers of each state are reported every day and we just see the rise in numbers. But what actually do we interpret just by seeing numbers? 

For this blog, I have used the Google Collab interface. We have used the libraries like NumPy, pandas, plotly. express and folium for the analysis.

We extract the data from the website . We then format the data to the required format and then use it for the analysis. Here in this blog we will be plotting graphs for analysis and also a map to show the numbers. 

df = pd.read_json(‘data.json’)
with open (‘data.json’) as f:
data = json.load(f)
df = df[“states_daily”]
df = pd.json_normalize(df)


We only have the state name abbreviations and the “Confirmed”, “Deceased” and “Recovered” columns at first. We then calculate the death rate and recovery rate of each state by dividing deceased and recovered with total numbers respectively. We then update the data frame with the latitude and longitude to plot the map, which we will see a bit later.

df[‘date’] = pd.to_datetime(df[‘date’])
df[‘month’] = df[‘date’].dt.month
df[[‘an’, ‘ap’, ‘ar’, ‘as’, ‘br’, ‘ch’, ‘ct’, ‘dd’, ‘dl’,
‘dn’, ‘ga’, ‘gj’, ‘hp’, ‘hr’, ‘jh’, ‘jk’, ‘ka’, ‘kl’, ‘la’, ‘ld’, ‘mh’,
‘ml’, ‘mn’, ‘mp’, ‘mz’, ‘nl’, ‘or’, ‘pb’, ‘py’, ‘rj’, ‘sk’, ‘tg’, ‘tn’, ‘tr’, ‘tt’, ‘un’, ‘up’, ‘ut’, ‘wb’]] = df[[‘an’, ‘ap’, ‘ar’, ‘as’, ‘br’, ‘ch’, ‘ct’, ‘dd’, ‘dl’,
‘dn’, ‘ga’, ‘gj’, ‘hp’, ‘hr’, ‘jh’, ‘jk’, ‘ka’, ‘kl’, ‘la’, ‘ld’, ‘mh’,
‘ml’, ‘mn’, ‘mp’, ‘mz’, ‘nl’, ‘or’, ‘pb’, ‘py’, ‘rj’, ‘sk’, ‘tg’, ‘tn’, ‘tr’, ‘tt’, ‘un’, ‘up’, ‘ut’, ‘wb’]].astype(str).astype(int)
df_confirm = df[df[“status”]==”Confirmed”]
df_recovered = df[df[“status”]==”Recovered”]
df_deceased = df[df[“status”]==”Deceased”]

df_c_mth = df_confirm.groupby(‘month’).sum()

df_r_mth = df_recovered.groupby(‘month’).sum()
df_d_mth = df_deceased.groupby(‘month’).sum()
df4 = df_c_mth.sum()
df4 = pd.DataFrame(df4)
df5 = df_d_mth.sum()
df5 = pd.DataFrame(df5)
df6 = df_r_mth.sum()
df6 = pd.DataFrame(df6)
Frame = [df4,df5,df6]
df_Total = pd.concat(Frame,axis=1)


Now we have created the df_Total data frame. We create the columns “death rate”, “recovery rate” and “state”.

df_Total[“Death Rate”]= df_Total[“Deceased”]/df_Total[“Confirmed”]
df_Total[“Recovery Rate”]= df_Total[“Recovered”]/df_Total[“Confirmed”]
state = [“Andaman and Nicobar”,”Andhra Pradesh”,”Arunachal Pradesh”,”Assam”,”Bihar”,”Chandigarh”,”Chhattisgarh”,”Daman and Diu”,”Delhi”,”Dadra and Nagar Haveli”,”Goa”,”Gujarat”,
“Himachal Pradesh”,”Haryana”,”Jharkhand”,”Jammu and Kashmir”,”Karnataka”,”Kerala”,”Ladakh”,”Lakshadweep”,”Maharashtra”,”Meghalaya”,”Manipur”,”Madhya Pradesh”,”Mizoram”,
“Nagaland”,”Orissa”,”Punjab”,”Puducherry”,”Rajasthan”,”Sikkim”,”Telangana”,”Tamil Nadu”,”Tripura”,”Uttar Pradesh”,”Uttaranchal”,”West Bengal”]
df_Total[“State”] = state


Statewise Covid-19 Analysis data

This data frame has to be updated with the latitude and longitude of the states, such that we would be able to plot the map. The data is available on the Kaggle website. We can download the CSV file and update the data frame.

coordinates = pd.read_csv(‘state wise centroids_2001.csv’)
df_an = {‘State’: ‘Ladakh’, “Latitude”: 34.152588, ‘Longitude’: 77.577049}
coordinates = coordinates.append(df_an, ignore_index = True)
df_an = {‘State’: ‘Telangana’, “Latitude”: 18.1124, ‘Longitude’: 79.0193}
coordinates = coordinates.append(df_an, ignore_index = True)
coordinates.sort_values(by=[‘State’], inplace=True)
Final = pd.merge(df_Total,coordinates,on=”State”, how=”inner”)

Statewise Covid-19 Analysis merge

The final dataset that we get after feature engineering is this.  Now, this is the completed data frame. We have used libraries like NumPy and pandas to complete the feature engineering. For plotting the graph we will be using and for the map folium.

 This is the data frame that we will be using to plot the graphs and the map.


We plot the graphs for the columns, “Confirmed”, “Deceased” and “Recovered”.,x=”State”,y=”Confirmed”,color=”Confirmed”,color_continuous_scale=[“Green”,”Orange”,”Red”],title=”Covid Confirmed Cases”)

Statewise Covid-19 Analysis plot,x=”State”,y=”Deceased”,color=”Deceased”,color_continuous_scale=[“Green”,”Orange”,”Red”],title=”Covid Death Cases”)

continue,x=”State”,y=”Recovered”,color=”Recovered”,color_continuous_scale=[“Red”,”Orange”,”Green”],title=”Covid Recovered Cases”)

recovered cases


From the above-plotted graphs, we find that Maharastra has the highest number of cases reported and the highest number of death. But from this we cannot conclude that Maharastra is the worst affected since it also has its recovered numbers high. It is important that we look into the next two columns, i.e the recovery rate and the death rate. Those are the numbers that actually show how the state is taking measures for the virus. The more confirmed reveals that more testing has been carried in the state which is a positive note in curbing the virus.

Thus we plot the death rate and recovery rate to know about the numbers.,x=”State”,y=”Death Rate”,color=”Death Rate”,color_continuous_scale= “Green”,”Orange”,”Red”],title=”Death Rates”)

death rates,x=”State”,y=”Recovery Rate”,color=”Recovery Rate”,color_continuous_scale=[“Red”,”Orange”,”Green”],title=”Recovery Rate”)

recovery rate 2


From the above graph, we can interpret that the highest death rate is in the state of Punjab. This clearly shows that the state has to take more action.

From the recovery rate graph, it is positive to see that, most of the states have a dark green color which means that they have a high rate of recovery. The ones with the lighter colors, have to work more to increase their recovery rate. The higher the recovery rate and lower the death rate shows that the state is working well against the virus.


Then we plot an interactive map, such that we would be able to view the numbers state-wise upon hovering in them. For this, we use the folium library.

# retreiving the data from final table and plotting it on the INDIA map
# creating the map object zooming on INDIA, location here shows the lat and long of INDIA
india = folium.Map(location = [20.5937,78.9629],zoom_start=4.5)
#adding to map
for state,lat,long,conf,Dec,Recov,drate,rrate in zip(list(Final[‘State’]),list(Final[‘Latitude’]),list(Final[‘Longitude’]),list(Final[‘Confirmed’]),list(Final[‘Deceased’]),
list(Final[‘Recovered’]),list(Final[‘Death Rate’]),list(Final[‘Recovery Rate’])):
#for creating circle marker
folium.CircleMarker(location = [lat,long],
radius = 5,
fill = True,
#for creating marker
folium.Marker(location = [lat,long],
# adding information that need to be displayed on popup
popup=folium.Popup((‘<strong>State : ‘+str(state)+'</strong> <br>’ +
‘<strong>Confirmed : ‘+str(conf)+'</strong><br>’ +
‘<strong><font color= red>Deceased : </font>’+str(Dec)+'</strong><br>’ +
‘<strong><font color=green>Recovered : </font>’+str(Recov)+'</strong><br>’ +
‘<strong>Death Rate : ‘+str(drate)+'</strong><br>’ +
‘<strong>Recovery Rate : ‘+str(rrate)+'</strong>’ ),max_width=200)).add_to(india)
#to show the map

From this map, we will be able to interpret the data in an interactive way. On clicking each location we get the data for that particular state. Thus this way we can get the data for the state required.


Thus, we can conclude that the numbers are just the cases reported while the rates reveal the counter steps taken by the states. It is important that all the states aim to keep the death rates low and recovery rates high.

Author Linkedin: Linkedin

The media shown in this article are not owned by Analytics Vidhya and is used at the Author’s discretion

About the Author

Nandita S

Our Top Authors

Download Analytics Vidhya App for the Latest blog/Article

Leave a Reply Your email address will not be published. Required fields are marked *