X-Git-Url: https://git.njae.me.uk/?p=covid19.git;a=blobdiff_plain;f=international_comparison.py;h=3764683b87caa5e9c38796aeb984517c7fae5d7f;hp=213560930552e1ba777f427035050c1c57d16b44;hb=HEAD;hpb=5afedd66506be7575034ae6deebcfaa7c2ced978 diff --git a/international_comparison.py b/international_comparison.py index 2135609..3764683 100644 --- a/international_comparison.py +++ b/international_comparison.py @@ -18,6 +18,7 @@ from sqlalchemy import create_engine import matplotlib as mpl import matplotlib.pyplot as plt plt.ioff() +# %matplotlib inline # %% @@ -30,36 +31,42 @@ engine = create_engine(connection_string) # %% DEATH_COUNT_THRESHOLD = 10 -COUNTRIES_CORE = tuple(sorted('IT DE UK ES IE FR BE'.split())) -COUNTRIES_NORDIC = tuple('SE NO DK FI UK'.split()) -COUNTRIES_FRIENDS = tuple('IT UK ES BE SI MX'.split()) +COUNTRIES_CORE = tuple(sorted('ITA DEU GBR ESP IRL FRA BEL'.split())) +# COUNTRIES_NORDIC = tuple('SE NO DK FI UK'.split()) +COUNTRIES_FRIENDS = tuple('ITA GBR ESP BEL SVN MEX'.split()) # COUNTRIES_FRIENDS = 'IT UK ES BE SI PT'.split() -COUNTRIES_AMERICAS = ('AG', 'AR', 'AW', 'BS', 'BB', 'BZ', 'BM', 'BO', 'BR', 'VG', 'KY', # excluding Canada and USA - 'CL', 'CO', 'CR', 'CU', 'CW', 'DM', 'DO', 'EC', 'SV', 'GL', 'GD', 'GT', - 'GY', 'HT', 'HN', 'JM', 'MX', 'MS', 'NI', 'PA', 'PY', 'PE', 'PR', 'KN', - 'LC', 'VC', 'SX', 'SR', 'TT', 'TC', 'VI', 'UY', 'VE') -COUNTRIES_OF_INTEREST = tuple(set(COUNTRIES_CORE + COUNTRIES_FRIENDS)) -COUNTRIES_ALL = tuple(set(COUNTRIES_CORE + COUNTRIES_FRIENDS + COUNTRIES_NORDIC + COUNTRIES_AMERICAS)) +# COUNTRIES_AMERICAS = ('AG', 'AR', 'AW', 'BS', 'BB', 'BZ', 'BM', 'BO', 'BR', 'VG', 'KY', # excluding Canada and USA +# 'CL', 'CO', 'CR', 'CU', 'CW', 'DM', 'DO', 'EC', 'SV', 'GL', 'GD', 'GT', +# 'GY', 'HT', 'HN', 'JM', 'MX', 'MS', 'NI', 'PA', 'PY', 'PE', 'PR', 'KN', +# 'LC', 'VC', 'SX', 'SR', 'TT', 'TC', 'VI', 'UY', 'VE') +# COUNTRIES_OF_INTEREST = tuple(set(COUNTRIES_CORE + COUNTRIES_FRIENDS)) +# COUNTRIES_ALL = tuple(set(COUNTRIES_CORE + COUNTRIES_FRIENDS + COUNTRIES_NORDIC + COUNTRIES_AMERICAS)) # %% -query_string = f'''select report_date, geo_id, deaths_weekly, culm_deaths +query_string = f'''select date, country_code, deaths_weekly, culm_deaths from weekly_cases -where geo_id in {COUNTRIES_CORE} -order by report_date, geo_id''' +where country_code in {COUNTRIES_CORE} +order by date, country_code''' country_data = pd.read_sql_query(query_string, engine, - index_col = 'report_date', - parse_dates = ['report_date'] + index_col = 'date', + parse_dates = ['date'] ) # %% -deaths_culm = country_data.pivot(columns='geo_id', values='culm_deaths') +deaths_culm = country_data.pivot(columns='country_code', values='culm_deaths') +# %% +# country_data + +# %% +# deaths_culm + # %% ax = deaths_culm.loc['2020-03-15':].plot(figsize=(10, 6), title="Total deaths, linear") ax.set_xlabel(f"Date") @@ -70,7 +77,7 @@ plt.savefig('covid_deaths_total_linear.png') # %% -deaths_weekly = country_data.pivot(columns='geo_id', values='deaths_weekly') +deaths_weekly = country_data.pivot(columns='country_code', values='deaths_weekly') # %% @@ -83,7 +90,7 @@ plt.savefig('covid_deaths_per_week.png') # %% -ax = deaths_weekly.iloc[-6:].plot(figsize=(10, 6), title="Deaths per week")#, ylim=(-10, 100)) +ax = deaths_weekly.iloc[-6:].plot(figsize=(10, 6), title="Deaths per week, last 6 weeks")#, ylim=(-10, 100)) ax.set_xlabel("Date") text_x_pos = deaths_weekly.last_valid_index() + pd.Timedelta(days=0.5)