# For Interactive graphs -> https://nbviewer.org/github/yogeshkumar22/Covid19/blob/main/Covid_19_data_analysis_project.ipynb
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# for better interactive visualization
import plotly.graph_objects as go
import plotly.express as px
import warnings
warnings.filterwarnings('ignore')
# !pip install --upgrade plotly
# !pip install -U kaleido
import plotly.io as pio
pio.renderers.default = "png"
import os
files=os.listdir('/content/Covid-19')
files
### Create a function to make our task simpler as we have to read data again & again
def read_data(path,filename):
return pd.read_csv(path+'/'+filename)
path='/content/Covid-19'
world_data=read_data(path,'worldometer_data.csv')
day_wise=read_data(path,files[1])
group_data=read_data(path,files[4])
usa_data=read_data(path,files[0])
province_data=read_data(path,files[5])
world_data.columns
columns=['TotalCases','TotalDeaths','TotalRecovered','ActiveCases']
for i in columns:
fig=px.treemap(world_data[0:20],values=i,path=['Country/Region'],template="plotly_dark",title="<b>TreeMap representation of Countries w.r.t. their {}</b>".format(i))
fig.show()
fig=px.line(day_wise,x="Date",y=["Confirmed","Deaths","Recovered","Active"],title="covid cases w.r.t. date",template="plotly_dark")
fig.show()
pop_test_ratio=world_data.iloc[0:20]['Population']/world_data.iloc[0:20]['TotalTests']
pop_test_ratio
fig=px.bar(world_data.iloc[0:20],color='Country/Region',y=pop_test_ratio,x='Country/Region',template="plotly_dark",title="<b>population to tests done ratio</b>")
fig.show()
fig=px.bar(world_data.iloc[0:20],x='Country/Region',y=['Serious,Critical','TotalDeaths','TotalRecovered','ActiveCases','TotalCases'],template="plotly_dark")
fig.update_layout({'title':"Coronavirus cases w.r.t. time"})
fig.show()
world_data.head()
world_data['Country/Region'].nunique()
fig=px.bar(world_data.iloc[0:20],y='Country/Region',x='TotalCases',color='TotalCases',text="TotalCases")
fig.update_layout(template="plotly_dark",title_text="<b>Top 20 countries of Total confirmed cases</b>")
fig.show()
fig=px.bar(world_data.sort_values(by='TotalDeaths',ascending=False)[0:20],y='Country/Region',x='TotalDeaths',color='TotalDeaths',text="TotalDeaths")
fig.update_layout(template="plotly_dark",title_text="<b>Top 20 countries of Total deaths</b>")
fig.show()
fig=px.bar(world_data.sort_values(by='ActiveCases',ascending=False)[0:20], y='Country/Region',x='ActiveCases',color='ActiveCases',text='ActiveCases')
fig.update_layout(template="plotly_dark",title_text="<b>Top 20 countries of Total Active cases")
fig.show()
fig=px.bar(world_data.sort_values(by='TotalRecovered',ascending=False)[:20],y='Country/Region',x='TotalRecovered',color='TotalRecovered',text='TotalRecovered')
fig.update_layout(template="plotly_dark",title_text="<b>Top 20 countries of Total Recovered")
fig.show()
world_data.columns
world_data[0:15]['Country/Region'].values
labels=world_data[0:15]['Country/Region'].values
cases=['TotalCases','TotalDeaths','TotalRecovered','ActiveCases']
for i in cases:
fig=px.pie(world_data[0:15],values=i,names=labels,template="plotly_dark",hole=0.3,title=" {} Recordeded w.r.t. to WHO Region of 15 worst effected countries ".format(i))
fig.show()
deaths_to_confirmed=((world_data['TotalDeaths']/world_data['TotalCases']))
fig = px.bar(world_data,x='Country/Region',y=deaths_to_confirmed)
fig.update_layout(title={'text':"Death to confirmed ratio of some worst effected countries",'xanchor':'left'},template="plotly_dark")
fig.show()
deaths_to_recovered=((world_data['TotalDeaths']/world_data['TotalRecovered']))
fig = px.bar(world_data,x='Country/Region',y=deaths_to_recovered)
fig.update_layout(title={'text':"Death to recovered ratio of some worst effected countries",'xanchor':'left'},template="plotly_dark")
fig.show()
tests_to_confirmed=((world_data['TotalTests']/world_data['TotalCases']))
fig = px.bar(world_data,x='Country/Region',y=tests_to_confirmed)
fig.update_layout(title={'text':"Tests to confirmed ratio of some worst effected countries",'xanchor':'left'},template="plotly_dark")
fig.show()
serious_to_death=((world_data['Serious,Critical']/world_data['TotalDeaths']))
fig = px.bar(world_data,x='Country/Region',y=serious_to_death)
fig.update_layout(title={'text':"serious to Death ratio of some worst effected countries",'xanchor':'left'},template="plotly_dark")
fig.show()
group_data.head()
from plotly.subplots import make_subplots ## for creating subplots in plotly
import plotly.graph_objects as go
def country_visualization(group_data,country):
data=group_data[group_data['Country/Region']==country]
df=data.loc[:,['Date','Confirmed','Deaths','Recovered','Active']]
fig = make_subplots(rows=1, cols=4,subplot_titles=("Confirmed", "Active", "Recovered",'Deaths'))
fig.add_trace(
go.Scatter(name="Confirmed",x=df['Date'],y=df['Confirmed']),
row=1, col=1
)
fig.add_trace(
go.Scatter(name="Active",x=df['Date'],y=df['Active']),
row=1, col=2
)
fig.add_trace(
go.Scatter(name="Recovered",x=df['Date'],y=df['Recovered']),
row=1, col=3
)
fig.add_trace(
go.Scatter(name="Deaths",x=df['Date'],y=df['Deaths']),
row=1, col=4
)
fig.update_layout(height=600, width=1000, title_text="Date Vs Recorded Cases of {}".format(country),template="plotly_dark")
fig.show()
country_visualization(group_data,'India')
country_visualization(group_data,'US')