Do check prev post: Covid19_StateWise_Analysis_India_Part1
Here we trying to focus on what will be the confirmed case count on the
last day of lockdown version-02 in India, the entire analysis is based on
growth rate technique. Let’s import
required modules
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.express as px
import plotly.offline as py
import plotly.graph_objs as go
py.init_notebook_mode(connected=True)
import folium
import seaborn as sns
import os
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.express as px
import plotly.offline as py
import plotly.graph_objs as go
py.init_notebook_mode(connected=True)
import folium
import seaborn as sns
import os
import datetime
Let try to find out growth rate, considering the data from 30th
Jan
confirmed_df =
pd.read_csv('https://raw.githubusercontent.com/CSSEGISandData/'+
'COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/'
+'time_series_covid19_confirmed_global.csv')
india_sel = confirmed_df[confirmed_df['Country/Region']=='India'].loc[:'4/13/20']
india_confirmed_list = india_sel.values.tolist()[0]
india_confirmed_list[4]
growth_diff = []
for i in range(4,len(india_confirmed_list)):
if (i == 4) or india_confirmed_list[i-1] == 0 :
growth_diff.append(india_confirmed_list[i])
else:
growth_diff.append(india_confirmed_list[i] / india_confirmed_list[i-1])
growth_factor = sum(growth_diff)/len(growth_diff)
print('Average growth factor',growth_factor)
'COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/'
+'time_series_covid19_confirmed_global.csv')
india_sel = confirmed_df[confirmed_df['Country/Region']=='India'].loc[:'4/13/20']
india_confirmed_list = india_sel.values.tolist()[0]
india_confirmed_list[4]
growth_diff = []
for i in range(4,len(india_confirmed_list)):
if (i == 4) or india_confirmed_list[i-1] == 0 :
growth_diff.append(india_confirmed_list[i])
else:
growth_diff.append(india_confirmed_list[i] / india_confirmed_list[i-1])
growth_factor = sum(growth_diff)/len(growth_diff)
print('Average growth factor',growth_factor)
#OUTPUT: GROWTH RATE
Average growth factor
1.0637553331032963
Lets now calculate the next twenty 21 days case count and plot it in
chart
x_axis_prediction_dt =
[]
dates = list(confirmed_df.columns[4:])
dates = list(pd.to_datetime(dates))
#we will add one day to the last day till which we have data
start_date = dates[len(dates) - 1]
for i in range(21):
date = start_date + datetime.timedelta(days=1)
x_axis_prediction_dt.append(date)
start_date = date
# Get the last available day total number
previous_day_cases = confirmed_df[confirmed_df['Country/Region']=='India'].iloc[:,-1]
# Converting series to float value
previous_day_cases = previous_day_cases.iloc[0]
y_axis_predicted_next21days_cases = []
for i in range(21):
predicted_value = previous_day_cases * growth_factor
y_axis_predicted_next21days_cases.append(predicted_value)
previous_day_cases = predicted_value
# print(previous_day_cases)
#add Graph
fig1=go.Figure()
fig1.add_trace(go.Scatter(x=x_axis_prediction_dt,
y=y_axis_predicted_next21days_cases,
name='India'
))
fig1.layout.update(title_text='COVID-19 next twenty one prediction',xaxis_showgrid=False, yaxis_showgrid=False, width=800,
height=500,font=dict(
# family="Courier New, monospace",
size=12,
color="white"
))
fig1.layout.plot_bgcolor = 'Black'
fig1.layout.paper_bgcolor = 'Black'
fig1.show()
dates = list(confirmed_df.columns[4:])
dates = list(pd.to_datetime(dates))
#we will add one day to the last day till which we have data
start_date = dates[len(dates) - 1]
for i in range(21):
date = start_date + datetime.timedelta(days=1)
x_axis_prediction_dt.append(date)
start_date = date
# Get the last available day total number
previous_day_cases = confirmed_df[confirmed_df['Country/Region']=='India'].iloc[:,-1]
# Converting series to float value
previous_day_cases = previous_day_cases.iloc[0]
y_axis_predicted_next21days_cases = []
for i in range(21):
predicted_value = previous_day_cases * growth_factor
y_axis_predicted_next21days_cases.append(predicted_value)
previous_day_cases = predicted_value
# print(previous_day_cases)
#add Graph
fig1=go.Figure()
fig1.add_trace(go.Scatter(x=x_axis_prediction_dt,
y=y_axis_predicted_next21days_cases,
name='India'
))
fig1.layout.update(title_text='COVID-19 next twenty one prediction',xaxis_showgrid=False, yaxis_showgrid=False, width=800,
height=500,font=dict(
# family="Courier New, monospace",
size=12,
color="white"
))
fig1.layout.plot_bgcolor = 'Black'
fig1.layout.paper_bgcolor = 'Black'
fig1.show()
Post Reference: Vikram Aristocratic Elfin Share