Analyze Corona Virus Cases In India

Corona Virus Cases In India By State - last updated March 24, 2020

Below data has been copied from following site mohfw.gov.in

In [15]:
df.sort_values(by='Confirmed_Indian_National',ascending=False)
Out[15]:
Confirmed_Indian_National Confirmed_Foreign_National Cured Death
Name_of_State_UT
Kerala 87 8 4 0
Maharashtra 84 3 0 2
Karnataka 37 0 2 1
Uttar Pradesh 32 1 9 0
Rajasthan 31 2 3 0
Delhi 30 1 6 1
Gujarat 29 0 0 1
Telengana 22 10 1 0
Punjab 21 0 0 1
Ladakh 13 0 0 0
Haryana 12 14 11 0
Tamil Nadu 10 2 1 0
Andhra Pradesh 7 0 0 0
West Bengal 7 0 0 1
Madhya Pradesh 7 0 0 0
Chandigarh 6 0 0 0
Jammu and Kashmir 4 0 0 0
Himachal Pradesh 3 0 0 1
Uttarakhand 3 0 0 0
Bihar 2 0 0 1
Odisha 2 0 0 0
Puducherry 1 0 0 0
Chhattisgarh 1 0 0 0
In [90]:
df[['Confirmed_Indian_National']].plot.bar()
Out[90]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f2caba17d10>
In [90]:
df[['Confirmed_Indian_National']].plot.bar()
Out[90]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f2caba17d10>

In this post, I have explained, how we can analyze and plot the Corona Virus Cases.

Let us import the Python Pandas packages.

In [1]:
import pandas as pd
import matplotlib.pyplot as plt

we need matplotlib pyplot to plot the charts.

If you have your notebook launched on Linux then, you can use cat command to look at first two rows.

In [2]:
!cat data/india_corona_virus_cases.csv | head -2

Other wise Pandas way is using head() method as shown below.

In [3]:
df_india = pd.read_csv('data/india_corona_virus_cases.csv',encoding='UTF-8')
In [4]:
df_india.head()
Out[4]:
Sno Name_of_State_UT Confirmed_Indian_National Confirmed_Foreign_National Cured Death
0 1 Andhra Pradesh 7 0 0 0
1 2 Bihar 2 0 0 1
2 3 Chhattisgarh 1 0 0 0
3 4 Delhi 30 1 6 1
4 5 Gujarat 29 0 0 1

Lets drop the redundant column Sno from our data frame using the df.drop method.

In [5]:
df_india.drop(columns=['Sno'],inplace=True)
In [6]:
df_india.head(2)
Out[6]:
Name_of_State_UT Confirmed_Indian_National Confirmed_Foreign_National Cured Death
0 Andhra Pradesh 7 0 0 0
1 Bihar 2 0 0 1

Let us set the index to column 'Name_of_State_UT' using df.set_index() method.

In [7]:
df = df_india.set_index('Name_of_State_UT')

We can sort our data frame by the most number of domestic Corona virus cases per state in India. Let us use pandas sort_values method to which we can feed the column by which we want to sort as shown below.

In [14]:
df.sort_values(by='Confirmed_Indian_National',ascending=False).head(2)
Out[14]:
Confirmed_Indian_National Confirmed_Foreign_National Cured Death
Name_of_State_UT
Kerala 87 8 4 0
Maharashtra 84 3 0 2

Let us check how many total domestic cases in India so far.

In [9]:
df.Confirmed_Indian_National.sum()
Out[9]:
451

How about foreign national Corona Virus cases in india.

In [10]:
df.Confirmed_Foreign_National.sum()
Out[10]:
41

Lets us plot few bar plots to visualize the Corona Virus cases in India.

In [11]:
df[['Confirmed_Indian_National']].plot.bar()
Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fc70de20f50>
In [12]:
df[['Confirmed_Foreign_National']].plot.bar()
Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fc70d301410>
In [13]:
df[['Confirmed_Indian_National','Confirmed_Foreign_National']].plot.bar()
Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fc70d1c4250>