Last active
September 3, 2020 17:40
-
-
Save pepijndevos/8a31a29dc70795a98fc616b94c2f8b4e to your computer and use it in GitHub Desktop.
Plot reported cases since reaching 100 cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
#cutoff = 100 | |
def flip(name): | |
df = pd.read_csv(name) | |
del df['Lat'] | |
del df['Long'] | |
df = df.groupby('Country/Region').sum().T | |
dates = pd.to_datetime(df.index) | |
df.index = dates#(dates-dates[-1]).days | |
return df | |
df_c = flip("csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv") | |
del df_c['Holy See'] | |
df_r = flip("csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv") | |
df_d = flip("csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv") | |
df = df_c-df_r-df_d | |
pop = pd.read_html("https://en.wikipedia.org/wiki/List_of_countries_by_population_%28United_Nations%29", attrs={'id': 'main'})[0] | |
popmap = {} | |
for idx, val in pop.iterrows(): | |
c = val['Country/Territory'] | |
if "[" in c: | |
c = c[:-3] | |
popmap[c] = val['Population(1 July 2019)'] | |
reldf = df[:] | |
for idx in reldf: | |
try: | |
reldf[idx] /= popmap[idx] | |
except KeyError: | |
del reldf[idx] | |
print(idx) | |
#for col in df: | |
# days = df[col].gt(cutoff).idxmax() | |
#df[col] = df[col].shift(-days) | |
#df = df.loc[:, df.max() >= cutoff] | |
#df = np.log(df).diff().rolling(window=7).mean().dropna(axis=1, thresh=3) | |
keys = ['Germany', 'Austria', 'Netherlands', 'France', 'Sweden', 'Denmark', 'Switzerland', 'Greece', 'Turkey', 'Russia'] | |
#keys = ['Netherlands'] | |
reldf[keys].plot() | |
#reldf[keys].diff().rolling(window=7).mean().plot() | |
#df.plot(logy=False, marker='.') | |
#plt.xlabel('Days') | |
plt.ylabel('Cases per inhabitant')# per inhabitant') | |
plt.grid(True) | |
#df.plot(logy=True) | |
#plt.xlim([-30, 0]) | |
#plt.ylim([0, 0.5]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment