14LG tzBxS6oOsaad9J6gb1GQn2CDEcGL

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

importinhg libraries

# importing pandas library to visualize data


import pandas as pd
# importing matoplotlib library
import matplotlib.pyplot as plt
# importing matplot style
from matplotlib import style
# impoting ggplot
style.use('ggplot')
%matplotlib inline
# importing seaborn library
import seaborn as sns
# importing plotly library
import plotly
import plotly.express as px
import plotly.graph_objects as go
plt.rcParams['figure.figsize']=17,8

from plotly.offline import init_notebook_mode,plot,iplot


# importing folium
import folium

importing �le named covid cases in india with panda

# reading file with pandas library


df = pd.read_excel('Covid cases in India.xlsx')
df

Total Confirmed Total Confirmed


Name of
no cases (Indian cases ( Foreign Cured Death
State / UT
National) National )

Andhra
0 1 12 0 1 0
Pradesh

1 2 Chhattisgarh 6 0 0 0

2 3 Delhi 38 1 6 1

3 4 Gujarat 43 0 0 3

4 5 Haryana 16 14 11 0

Himachal
5 6 4 0 0 1
Pradesh

6 7 Karnataka 20 0 3 2

7 8 Kerala 131 7 11 0

Madhya

1 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

Madhya
8 9 23 0 0 1
Pradesh

9 10 Maharashtra 144 3 15 4

10 11 Odisha 3 0 0 0

11 12 Puducherry 1 0 0 0

12 13 Punjab 29 0 0 1

13 14 Rajasthan 41 2 3 0

14 15 Tamil Nadu 32 3 1 1

15 16 Telengana 34 11 1 0

16 17 Chandigarh 7 0 0 0

Jammu and
17 18 18 0 1 1
Kashmir

18 19 Ladakh 13 0 0 0

19 20 Uttar Pradesh 42 1 11 0

20 21 Uttarakhand 4 0 0 0

21 22 West Bengal 11 0 0 1

22 23 Bihar 7 0 0 1

23 24 Mizoram 1 0 0 0

# droping no column from data


df.drop(['no'],axis=1,inplace=True)
df

Total Confirmed Total Confirmed


Name of
cases (Indian cases ( Foreign Cured Death
State / UT
National) National )

Andhra
0 12 0 1 0
Pradesh

1 Chhattisgarh 6 0 0 0

2 Delhi 38 1 6 1

3 Gujarat 43 0 0 3

4 Haryana 16 14 11 0

Himachal
5 4 0 0 1
Pradesh

6 Karnataka 20 0 3 2

7 Kerala 131 7 11 0

Madhya
8 23 0 0 1
Pradesh

2 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

9 Maharashtra 144 3 15 4

10 Odisha 3 0 0 0

11 Puducherry 1 0 0 0

12 Punjab 29 0 0 1

13 Rajasthan 41 2 3 0

14 Tamil Nadu 32 3 1 1

15 Telengana 34 11 1 0

16 Chandigarh 7 0 0 0

Jammu and
17 18 0 1 1
Kashmir

18 Ladakh 13 0 0 0

19 Uttar Pradesh 42 1 11 0

20 Uttarakhand 4 0 0 0

21 West Bengal 11 0 0 1

22 Bihar 7 0 0 1

23 Mizoram 1 0 0 0

# crating new column called total cases


df['Total Cases'] = df['Total Confirmed cases (Indian National)']+df
df

Total
Total
Confirmed
Name of Confirmed Total
cases ( Cured Death
State / UT cases (Indian Cases
Foreign
National)
National )

Andhra
0 12 0 1 0 12
Pradesh

1 Chhattisgarh 6 0 0 0 6

2 Delhi 38 1 6 1 39

3 Gujarat 43 0 0 3 43

4 Haryana 16 14 11 0 30

Himachal
5 4 0 0 1 4
Pradesh

6 Karnataka 20 0 3 2 20

7 Kerala 131 7 11 0 138

Madhya
8 23 0 0 1 23
Pradesh

9 Maharashtra 144 3 15 4 147

3 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

9 Maharashtra 144 3 15 4 147

10 Odisha 3 0 0 0 3

11 Puducherry 1 0 0 0 1

12 Punjab 29 0 0 1 29

13 Rajasthan 41 2 3 0 43

14 Tamil Nadu 32 3 1 1 35

15 Telengana 34 11 1 0 45

16 Chandigarh 7 0 0 0 7

Jammu and
17 18 0 1 1 18
Kashmir

18 Ladakh 13 0 0 0 13

19 Uttar Pradesh 42 1 11 0 43

20 Uttarakhand 4 0 0 0 4

21 West Bengal 11 0 0 1 11

22 Bihar 7 0 0 1 7

# printing total cases in india


Total_Cases_Overall=df['Total Cases'].sum()
print('Total Overall cases in India till now is',Total_Cases_Overall)
Total Overall cases in India till now is 729

# creating new column active cases


df['Active Cases']=df['Total Cases']-(df['Cured']+df['Death'])
df

Total Total
Confirmed Confirmed
Name of Total Active
cases cases ( Cured Death
State / UT Cases Cases
(Indian Foreign
National) National )

Andhra
0 12 0 1 0 12 11
Pradesh

1 Chhattisgarh 6 0 0 0 6 6

2 Delhi 38 1 6 1 39 32

3 Gujarat 43 0 0 3 43 40

4 Haryana 16 14 11 0 30 19

Himachal
5 4 0 0 1 4 3
Pradesh

6 Karnataka 20 0 3 2 20 15

7 Kerala 131 7 11 0 138 127

4 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

7 Kerala 131 7 11 0 138 127

Madhya
8 23 0 0 1 23 22
Pradesh

9 Maharashtra 144 3 15 4 147 128

10 Odisha 3 0 0 0 3 3

11 Puducherry 1 0 0 0 1 1

12 Punjab 29 0 0 1 29 28

13 Rajasthan 41 2 3 0 43 40

14 Tamil Nadu 32 3 1 1 35 33

15 Telengana 34 11 1 0 45 44

16 Chandigarh 7 0 0 0 7 7

Jammu and
17 18 0 1 1 18 16
Kashmir

18 Ladakh 13 0 0 0 13 13

Uttar
19 42 1 11 0 43 32
Pradesh

20 Uttarakhand 4 0 0 0 4 4

21 West Bengal 11 0 0 1 11 10

22 Bihar 7 0 0 1 7 6

# using style from matplotlib


df.style.background_gradient(cmap='Blues')

Total Total
Confirmed Confirmed
Name of Total Active
cases cases ( Cured Death
State / UT Cases Cases
(Indian Foreign
National) National )

Andhra
0 12 0 1 0 12 11
Pradesh

1 Chhattisgarh 6 0 0 0 6 6

2 Delhi 38 1 6 1 39 32

3 Gujarat 43 0 0 3 43 40

4 Haryana 16 14 11 0 30 19

Himachal
5 4 0 0 1 4 3
Pradesh

6 Karnataka 20 0 3 2 20 15

7 Kerala 131 7 11 0 138 127

Madhya
8 23 0 0 1 23 22

5 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

8 23 0 0 1 23 22
Pradesh

9 Maharashtra 144 3 15 4 147 128

10 Odisha 3 0 0 0 3 3

11 Puducherry 1 0 0 0 1 1

12 Punjab 29 0 0 1 29 28

13 Rajasthan 41 2 3 0 43 40

14 Tamil Nadu 32 3 1 1 35 33

15 Telengana 34 11 1 0 45 44

16 Chandigarh 7 0 0 0 7 7

Jammu and
17 18 0 1 1 18 16
Kashmir

18 Ladakh 13 0 0 0 13 13

19 Uttar Pradesh 42 1 11 0 43 32

20 Uttarakhand 4 0 0 0 4 4

21 West Bengal 11 0 0 1 11 10

22 Bihar 7 0 0 1 7 6

23 Mizoram 1 0 0 0 1 1

# Group by name and total active cases


Total_Active_Cases = df.groupby('Name of State / UT')['Total Cases']
Total_Active_Cases

Total Cases

Name of State / UT

Maharashtra 147

Kerala 138

Telengana 45

Uttar Pradesh 43

Gujarat 43

Rajasthan 43

Delhi 39

Tamil Nadu 35

Haryana 30

Punjab 29

Madhya Pradesh 23

Karnataka 20

6 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

Jammu and Kashmir 18

Ladakh 13

Andhra Pradesh 12

West Bengal 11

Bihar 7

Chandigarh 7

Goa 6

Chhattisgarh 6

Himachal Pradesh 4

Uttarakhand 4

Odisha 3

Manipur 1

Mizoram 1

Puducherry 1

Total_Active_Cases.style.background_gradient(cmap="Reds")

Total Cases

Name of State / UT

Maharashtra 147

Kerala 138

Telengana 45

Uttar Pradesh 43

Gujarat 43

Rajasthan 43

Delhi 39

Tamil Nadu 35

Haryana 30

Punjab 29

Madhya Pradesh 23

Karnataka 20

Jammu and Kashmir 18

Ladakh 13

Andhra Pradesh 12

7 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

Andhra Pradesh 12

West Bengal 11

Bihar 7

Chandigarh 7

Goa 6

Chhattisgarh 6

Himachal Pradesh 4

Uttarakhand 4

Odisha 3

Manipur 1

Mizoram 1

Puducherry 1

# graphical visualization

# representing in bar
df.plot(kind='bar',x='Name of State / UT',y='Total Cases')
plt.show()

8 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

plt.bar(df['Name of State / UT'],df['Total Cases'])


<BarContainer object of 26 artists>

# visualization using scatter


df.plot(kind='scatter',x='Name of State / UT',y = 'Total Cases')
plt.show()

9 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

plt.scatter(df['Name of State / UT'],df['Total Cases'])


<matplotlib.collections.PathCollection at 0x7ab740f19ea0>

# reading indian coordinates file


Indian_Cord = pd.read_excel('Indian Coordinates.xlsx')
Indian_Cord

Name of State / UT Latitude Longitude

0 Andaman And Nicobar 11.667026 92.735983

1 Andhra Pradesh 14.750429 78.570026

2 Arunachal Pradesh 27.100399 93.616601

3 Assam 26.749981 94.216667

4 Bihar 25.785414 87.479973

5 Chandigarh 30.719997 76.780006

6 Chhattisgarh 22.090420 82.159987

7 Dadra And Nagar Haveli 20.266578 73.016618

10 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

7 Dadra And Nagar Haveli 20.266578 73.016618

8 Delhi 28.669993 77.230004

9 Goa 15.491997 73.818001

10 Haryana 28.450006 77.019991

11 Himachal Pradesh 31.100025 77.166597

12 Union Territory of Jammu and Kashmir 33.450000 76.240000

13 Jharkhand 23.800393 86.419986

14 Karnataka 12.570381 76.919997

15 Kerala 8.900373 76.569993

16 Lakshadweep 10.562573 72.636867

17 Madhya Pradesh 21.300391 76.130019

18 Maharashtra 19.250232 73.160175

19 Manipur 24.799971 93.950017

20 Meghalaya 25.570492 91.880014

21 Mizoram 23.710399 92.720015

22 Nagaland 25.666998 94.116570

23 Orissa 19.820430 85.900017

24 Puducherry 11.934994 79.830000

25 Punjab 31.519974 75.980003

26 Rajasthan 26.449999 74.639981

27 Sikkim 27.333330 88.616647

28 Telengana 18.112400 79.019300

29 Tamil Nadu 12.920386 79.150042

30 Tripura 23.835404 91.279999

31 Uttar Pradesh 27.599981 78.050006

32 Uttarakhand 30.320409 78.050006

33 West Bengal 22.580390 88.329947

34 Union Territory of Ladakh 34.100000 77.340000

# merging file on Name of State / UT with file covid cases in india


df_full = pd.merge(Indian_Cord,df,on='Name of State / UT')
df_full

Total
Total
Confirmed
Confirmed
Name of cases ( Total
Latitude Longitude cases Cured Death

11 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

Latitude Longitude cases Cured Death


State / UT Foreign Cases
(Indian
National
National)
)

Andhra
0 14.750429 78.570026 12 0 1 0
Pradesh

1 Delhi 28.669993 77.230004 38 1 6 1

2 Haryana 28.450006 77.019991 16 14 11 0

3 Karnataka 12.570381 76.919997 20 0 3 2

4 Kerala 8.900373 76.569993 131 7 11 0

5 Maharashtra 19.250232 73.160175 144 3 15 4

6 Punjab 31.519974 75.980003 29 0 0 1

7 Rajasthan 26.449999 74.639981 41 2 3 0

8 Telengana 18.112400 79.019300 34 11 1 0

9 Tamil Nadu 12.920386 79.150042 32 3 1 1

Uttar
10 27.599981 78.050006 42 1 11 0

map=folium.Map(location=[20,70],zoom_start=4,tiles='Stamenterrain')

for lat,long,value, name in zip(df_full['Latitude'],df_full['Longitude'


folium.CircleMarker([lat,long],radius=value*0.8,popup=('<strong>State</

map
Make this Notebook Trusted to load map: File -> Trust Notebook
+

Leaflet (https://leafletjs.com) | Map tiles by Stamen Design (http://stamen.com), under CC BY 3.0 (http://creativecommons.org/licenses/
by/3.0). Data by © OpenStreetMap (http://openstreetmap.org), under CC BY SA (http://creativecommons.org/licenses/by-sa/3.0).

12 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

# getting data of global cases

dbd_india=pd.read_excel('per_day_cases.xlsx', parse_dates=True,sheet_name=
dbd_italy = pd.read_excel('per_day_cases.xlsx',parse_dates=True,sheet_name=
dbd_korea = pd.read_excel('per_day_cases.xlsx',parse_dates=True,sheet_name=
dbd_wuhan = pd.read_excel('per_day_cases.xlsx',parse_dates=True,sheet_name=

dbd_india

Total New Days after surpassing 100


Date
Cases Cases cases

0 2020-01-30 1 1 NaN

1 2020-01-31 1 0 NaN

2 2020-02-01 1 0 NaN

3 2020-02-02 2 1 NaN

4 2020-02-03 3 1 NaN

5 2020-02-04 3 0 NaN

6 2020-02-05 3 0 NaN

7 2020-02-06 3 0 NaN

8 2020-02-07 3 0 NaN

9 2020-02-08 3 0 NaN

10 2020-02-09 3 0 NaN

11 2020-02-10 3 0 NaN

12 2020-02-11 3 0 NaN

13 2020-02-12 3 0 NaN

14 2020-02-13 3 0 NaN

15 2020-02-14 3 0 NaN

16 2020-02-15 3 0 NaN

17 2020-02-16 3 0 NaN

18 2020-02-17 3 0 NaN

19 2020-02-18 3 0 NaN

13 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

20 2020-02-19 3 0 NaN

21 2020-02-20 3 0 NaN

22 2020-02-21 3 0 NaN

23 2020-02-22 3 0 NaN

24 2020-02-23 3 0 NaN

25 2020-02-24 3 0 NaN

26 2020-02-25 3 0 NaN

27 2020-02-26 3 0 NaN

28 2020-02-27 3 0 NaN

29 2020-02-28 3 0 NaN

30 2020-02-29 3 0 NaN

31 2020-03-01 3 0 NaN

32 2020-03-02 6 3 NaN

33 2020-03-03 9 3 NaN

34 2020-03-04 28 19 NaN

35 2020-03-05 30 2 NaN

36 2020-03-06 31 1 NaN

37 2020-03-07 34 3 NaN

38 2020-03-08 39 5 NaN

39 2020-03-09 43 4 NaN

40 2020-03-10 56 13 NaN

41 2020-03-11 62 6 NaN

42 2020-03-12 73 11 NaN

43 2020-03-13 82 9 NaN

44 2020-03-14 102 20 0.0

45 2020-03-15 113 11 1.0

46 2020-03-16 119 6 2.0

47 2020-03-17 142 23 3.0

48 2020-03-18 156 14 4.0

49 2020-03-19 194 38 5.0

50 2020-03-20 244 50 6.0

51 2020-03-21 271 27 7.0

# data visualization using matplotlib

14 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

# data visualization using matplotlib


fig = plt.figure(figsize=(10,5),dpi=200)
axes = fig.add_axes([0.1,0.1,0.8,0.8])
axes.bar(dbd_india['Date'],dbd_india['Total Cases'],color='blue')
axes.set_xlabel('Date')
axes.set_ylabel('Total Cases')
axes.set_title('confirmed cases in India')
plt.show()

# plotly expression
fig = px.bar(x=dbd_india['Date'],y=dbd_india["Total Cases"],title =
fig.show()

confirmed cases in india

250

200

15 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

150

y 100

50

0
Feb 2 Feb 9 Feb 16 Feb 23 Mar 1
2020

fig = px.bar(x=dbd_italy['Date'],y=dbd_italy["Total Cases"],title = 'confir


fig.show()

confirmed cases in italy

40k

30k
y

20k

10k

0
Feb 2 Feb 9 Feb 16 Feb 23 Mar 1
2020

fig = px.bar(x=dbd_korea['Date'],y=dbd_korea["Total Cases"],title = 'confir


fig.show()

16 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

confirmed cases in korea

9000

8000

7000

6000

5000
y

4000

3000

2000

1000

0
Jan 26 Feb 2 Feb 9 Feb 16 Feb 23 Mar 1
2020

fig = px.bar(x=dbd_wuhan['Date'],y=dbd_wuhan["Total Cases"],title = 'confir


fig.show()

confirmed cases in wuhan

70k

60k

50k

40k
y

30k

20k

10k

17 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

0
Jan 5 Jan 19 Feb 2 Feb 16
2020

fig=plt.figure(figsize=(10,5),dpi=200)
axes=fig.add_axes([0.1,0.1,0.8,0.8])
axes.plot(dbd_india["Date"],dbd_india["Total Cases"],color='blue',marker=
axes.set_xlabel("Date")
axes.set_ylabel("Total Cases")
axes.set_title("Confirmed cases in India")
plt.show()

#plotly Express

fig=px.scatter(dbd_india,x="Date",y="Total Cases",color='Total Cases',


fig.show()

Confirmed cases in India

250

200
Total Cases

150

18 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

Total Cases
100

50

Feb 2 Feb 9 Feb 16 Feb 23 Mar 1 Mar 8


2020

Date

fig=go.Figure()
fig.add_trace(go.Scatter(x=dbd_india['Date'],y=dbd_india['Total Cases'

250

200

150

100

50

Feb 2 Feb 9 Feb 16 Feb 23 Mar 1


2020

19 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

#Subplots using Bar Graph


from plotly.subplots import make_subplots

fig=make_subplots(
rows=2,cols=2,
specs=[[{"secondary_y":True},{"secondary_y":True}],[{"secondary_y"
subplot_titles=("S.Korea","Italy","India","Wuhan"))

fig.add_trace(go.Bar(x=dbd_korea['Date'],y=dbd_korea['Total Cases'],
marker=dict(color=dbd_korea['Total Cases'],coloraxis=

fig.add_trace(go.Bar(x=dbd_italy['Date'],y=dbd_italy['Total Cases'],
marker=dict(color=dbd_italy['Total Cases'],coloraxis=

fig.add_trace(go.Bar(x=dbd_india['Date'],y=dbd_india['Total Cases'],
marker=dict(color=dbd_india['Total Cases'],coloraxis=

fig.add_trace(go.Bar(x=dbd_wuhan['Date'],y=dbd_wuhan['Total Cases'],
marker=dict(color=dbd_wuhan['Total Cases'],coloraxis=

fig.update_layout(coloraxis=dict(colorscale='Bluered_r'),showlegend=False

fig.update_layout(plot_bgcolor='rgb(230,230,230)')

Total Cases in 4 Countries

S.Korea
8000
40k
6000
30k
4000 20k
2000 10k

0 0
Feb 2 Feb 16 Mar 1 Mar 15 Feb 2 Feb 16
2020 2020

India
60k
200
40k

100
20k

20 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

0 0
Feb 2 Feb 16 Mar 1 Mar 15 Feb 2020
2020

fig=make_subplots(
rows=2,cols=2,
specs=[[{"secondary_y":True},{"secondary_y":True}],[{"secondary_y"
subplot_titles=("S.Korea","Italy","India","Wuhan"))

fig.add_trace(go.Scatter(x=dbd_korea['Date'],y=dbd_korea['Total Cases'
marker=dict(color=dbd_korea['Total Cases'],coloraxis=

fig.add_trace(go.Scatter(x=dbd_italy['Date'],y=dbd_italy['Total Cases'
marker=dict(color=dbd_italy['Total Cases'],coloraxis=

fig.add_trace(go.Scatter(x=dbd_india['Date'],y=dbd_india['Total Cases'
marker=dict(color=dbd_india['Total Cases'],coloraxis=

fig.add_trace(go.Scatter(x=dbd_wuhan['Date'],y=dbd_wuhan['Total Cases'
marker=dict(color=dbd_wuhan['Total Cases'],coloraxis=

fig.update_layout(coloraxis=dict(colorscale='Bluered_r'),showlegend=False

fig.update_layout(plot_bgcolor='rgb(230,230,230)')

Total Cases in 4 Countries

S.Korea
8000
40k
6000

4000 20k
2000

0 0
Feb 2 Feb 16 Mar 1 Mar 15 Feb 2 Feb 16
2020 2020

India
60k
200
40k

100
20k

21 of 22 06/02/24, 10:09
AIDSEX2.ipynb - Colaboratory https://colab.research.google.com/drive/14LG_tzBxS...

0 0
Feb 2 Feb 16 Mar 1 Mar 15 Feb 2020
2020

22 of 22 06/02/24, 10:09

You might also like