text_plain_output_1.png image_output_1.png
import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data_path = '/kaggle/input/covid19-global-forecasting-week-4/train.csv'
data_train = pd.read_csv(data_path)

def add_daily_measures(df):
    df.loc[0, 'Daily Cases'] = df.loc[0, 'ConfirmedCases']
    df.loc[0, 'Daily Deaths'] = df.loc[0, 'Fatalities']
    for i in range(1, len(df)):
        df.loc[i, 'Daily Cases'] = df.loc[i, 'ConfirmedCases'] - df.loc[i - 1, 'ConfirmedCases']
        df.loc[i, 'Daily Deaths'] = df.loc[i, 'Fatalities'] - df.loc[i - 1, 'Fatalities']
    df.loc[0, 'Daily Cases'] = 0
    df.loc[0, 'Daily Deaths'] = 0
    return df

df_world = data_train.copy()
df_world = df_world.groupby('Date', as_index=False)['ConfirmedCases', 'Fatalities'].sum()
df_world = add_daily_measures(df_world)

df_usa = data_train.query("Country_Region=='US'")
df_usa = df_usa.groupby('Date', as_index=False)['ConfirmedCases', 'Fatalities'].sum()
df_usa = add_daily_measures(df_usa)
df_italy = data_train.query("Country_Region=='Italy'")
df_italy = df_italy.groupby('Date', as_index=False)['ConfirmedCases', 'Fatalities'].sum()
df_italy = add_daily_measures(df_italy)
df_spain = data_train.query("Country_Region=='Spain'")
df_spain = df_spain.groupby('Date', as_index=False)['ConfirmedCases', 'Fatalities'].sum()
df_spain = add_daily_measures(df_spain)
df_korea = data_train.query("Country_Region=='Korea, South'")
df_korea = df_korea.groupby('Date', as_index=False)['ConfirmedCases', 'Fatalities'].sum()
df_korea = add_daily_measures(df_korea)

data_flight = pd.read_csv('/kaggle/input/covid19/covid19_flight_countries_mod.csv')

data_daily_tested = pd.read_csv('/kaggle/input/covid19/full-list-covid-19-tests-per-day.csv')

df_usa_tested = data_daily_tested.query("Code=='USA'")
df_italy_tested = data_daily_tested.query("Entity=='Italy'")
df_spain_tested = data_daily_tested.query("Entity=='Spain'")
df_korea_tested = data_daily_tested.query("Entity=='South Korea'")

df_usa_merge = pd.merge(df_usa, df_usa_tested)
df_usa_merge = pd.merge(df_usa_merge, data_flight)
df_usa_merge.head()