Skip to content

Instantly share code, notes, and snippets.

@rvipandey
Last active June 27, 2020 14:34
Show Gist options
  • Save rvipandey/3b5498de244edebe7f6881f116d67fd7 to your computer and use it in GitHub Desktop.
Save rvipandey/3b5498de244edebe7f6881f116d67fd7 to your computer and use it in GitHub Desktop.
def stanalysis(statename,typ):
definestate=state_wise_daily[state_wise_daily.State_Name==statename]
finalstate= definestate.groupby(["Date","State_Name"])[["Confirmed","Deceased","Recovered"]].sum().reset_index().reset_index(drop=True)
createfigure(finalstate,typ,statename)
def createfigure(dataframe,typ,statename):
fig = go.Figure()
fig.add_trace(go.Scatter(x=dataframe["Date"], y=dataframe["Confirmed"],
mode="lines+text",
name='Confirmed',
marker_color='orange',
))
fig.add_trace(go.Scatter(x=dataframe["Date"], y=dataframe["Recovered"],
mode="lines+text",
name='Recovered',
marker_color='Green',
))
fig.add_trace(go.Scatter(x=dataframe["Date"], y=dataframe["Deceased"],
mode="lines+text",
name='Deceased',
marker_color='Red',
))
fig.add_shape(
# Line Vertical
dict(
type="line",
x0="2020-03-24",
y0=dataframe[typ].max(),
x1="2020-03-24",
line=dict(
color="red",
width=5)))
fig.add_annotation(
x="2020-03-24",
y=dataframe[typ].max(),
text="Lockdown Period",
font=dict(
family="Courier New, monospace",
size=14,
color="red"
),)
fig.add_annotation(
x="2020-04-24",
y=dataframe[typ].max(),
text="Month after lockdown",
font=dict(
family="Courier New, monospace",
size=14,
color="Green"
),)
fig.add_shape(
# Line Vertical
dict(
type="line",
x0="2020-04-24",
y0=dataframe[typ].max(),
x1="2020-04-24",
line=dict(
color="Green",
width=5)))
fig
fig.update_layout(
title='Evolution of Confirmed-Recovered-Deceased cases over time in '+statename,
template='gridon')
fig.show()
#if you want to get only one state result
stanalysis("Gujarat",'Recovered')
#For all states run below code
for states in state_wise_daily.State_Name.unique().tolist():
if(states!='Daman and Diu'):
stanalysis(states,'Recovered')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment