# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: covid
#     language: python
#     name: covid
# ---

# +
import numpy as np
import pandas as pd

# %matplotlib inline
import matplotlib.pyplot as plt
# -

pd.options.display.max_colwidth = 200

# ### Oxford University COVID-19 forecasting project data
#
# The data below was downloaded from the [Oxford University countermeasures database](https://www.notion.so/COVID-19-countermeasures-database-b532a58d6f944ef6982ab565627bdb08). See the website for a description of the data sources.

countermeasures_df = pd.read_csv("data/containment_measures_march23.csv")

countermeasures_df.head(1)

countermeasures_df[["Country", "Date Start", "Description of measure implemented"]].groupby("Country").head(10)

print(countermeasures_df["Country"].unique())

print(countermeasures_df["Implementing City"].unique())

print(countermeasures_df["Implementing State/Province"].unique())

# ### John Hopkins containment measures database
#
# The data is made available as part of the John Hopkins [Containment Measures Database](http://epidemicforecasting.org/containment). See the website in the link for a description of the data sources.

containment_df = pd.read_csv("data/countermeasures_db_johnshopkins_2020_03_30.csv")

containment_df.columns

print(containment_df["Country"].unique())

cases_df = containment_df[["Date", "Country", "Confirmed Cases", "Deaths"]]\
.loc[containment_df["Confirmed Cases"] > 3000]\
.pivot(index="Date", columns="Country", values="Confirmed Cases")

cases_df.plot(figsize=(16,8), title="Per-country growth in confirmed cases after the first 3000")\
.legend(bbox_to_anchor=(1,1))

deaths_df = containment_df[["Date", "Country", "Confirmed Cases", "Deaths"]]\
.loc[containment_df["Deaths"] > 100]\
.pivot(index="Date", columns="Country", values="Deaths")

deaths_df.plot(figsize=(16,8), title="Deaths per country after the first 100 deaths recorded")\
.legend(bbox_to_anchor=(1,1))

other_cm_cols = ['Unnamed: 0', 'Resumption', 'Diagnostic criteria loosened', 'Testing criteria', 'Date', 'Country',
                 'Confirmed Cases', 'Deaths']

countermeasures = list(filter(lambda m: m not in other_cm_cols, containment_df.columns))

cm_df = containment_df[countermeasures + ['Date', 'Country']].fillna(0)

cm_df[countermeasures] = cm_df[countermeasures].mask(cm_df[countermeasures] > 0, 1)

cm_df.groupby("Date").sum().plot(figsize=(16,8), title="Number of countries implementing measure by date")\
.legend(bbox_to_anchor=(1,1))



StarcoderdataJupyterScriptsDedupFiltered