Browse Source

tornado smoothing tests

main
parent
commit
d3ac50c0ca
  1. 24
      tornado.py

24
tornado.py

@ -4,6 +4,7 @@ import pandas as pd
import requests
import matplotlib
import json
import numpy as np
# %%
r = requests.get('https://disease.sh/v3/covid-19/historical/fr?lastdays=all')
@ -11,22 +12,35 @@ x = r.json()
#%%
df = pd.DataFrame(x['timeline'])
df = df.reset_index()
#%% convert index to datetime, messing things up
# df.index = pd.to_datetime(df.index, dayfirst=True)
# %%
df['daily_deaths'] = df['deaths'].diff()
df['daily_deaths_avg'] = df['daily_deaths'].rolling(7).mean()
df['death_change'] = df['daily_deaths'].diff()
df['death_change'] = df['daily_deaths_avg'].diff()
# %%
df.fillna(value=0, inplace=True)
poly = np.polyfit(df.index.values, df['daily_deaths_avg'].values, 5)
poly_tornado = np.poly1d(poly)(df.index.values)
# %%
df['tornado'] = poly_tornado
# %% Try to smooth the curve with interpolation
# df['death_change'] = df['death_change'].interpolate(method='cubic')
# %%
df['death_change'] = df['death_change'].rolling(5).mean()
#df['death_change'] = df['death_change'].rolling(3).mean()
# %%
# df.drop(columns=['cases', 'deaths', 'recovered'], inplace=True)
#%%
#df.plot()
df.plot(x='death_change', y='daily_deaths_avg')
df.plot(x='death_change', y='daily_deaths_avg')
Loading…
Cancel
Save