text_html_output_1.png text_plain_output_1.png
import datetime

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

train_df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
test_df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
submission_df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv')
train_df = train_df.drop(['Id'], axis=1)
train_df.rename(columns={'Country_Region': 'Country'}, inplace=True)
test_df.rename(columns={'Country_Region': 'Country'}, inplace=True)
train_df['Province_State'].fillna('None*', inplace=True)
test_df['Province_State'].fillna('None*', inplace=True)
renameCountryNames = {'Congo (Brazzaville)': 'Congo1', 'Congo (Kinshasa)': 'Congo2', "Cote d'Ivoire": "Côte d'Ivoire", 'Czechia': 'Czech Republic (Czechia)', 'Korea, South': 'South Korea', 'Saint Kitts and Nevis': 'Saint Kitts & Nevis', 'Saint Vincent and the Grenadines': 'St. Vincent & Grenadines', 'Taiwan*': 'Taiwan', 'US': 'United States'}
train_df.replace({'Country': renameCountryNames}, inplace=True)
test_df.replace({'Country': renameCountryNames}, inplace=True)
specific_countries = ['United States', 'United Kingdom', 'Netherlands']
days_df = train_df['Date'].apply(lambda dt: datetime.datetime.strptime(dt, '%Y-%m-%d') - datetime.datetime.strptime('2020-01-21', '%Y-%m-%d')).apply(lambda x: str(x).split()[0]).astype(int)
train_df['Days'] = days_df
days_df = test_df['Date'].apply(lambda dt: datetime.datetime.strptime(dt, '%Y-%m-%d') - datetime.datetime.strptime('2020-01-21', '%Y-%m-%d')).apply(lambda x: str(x).split()[0]).astype(int)
test_df['Days'] = days_df
all_countries = train_df['Country'].unique()
display(train_df.tail())
display(test_df.head())
ww_df = train_df.groupby('Date')[['ConfirmedCases', 'Fatalities']].sum().reset_index()
ww_df['new_case'] = ww_df['ConfirmedCases'] - ww_df['ConfirmedCases'].shift(1)
ww_df['new_deaths'] = ww_df['Fatalities'] - ww_df['Fatalities'].shift(1)
country_df = train_df.groupby(['Date', 'Country'])[['ConfirmedCases', 'Fatalities']].sum().reset_index()
target_date = country_df['Date'].max()
train_end_day = train_df['Days'].max()
test_start_day = test_df['Days'].min()
test_end_day = test_df['Days'].max()
display(country_df[country_df['Country'] == 'France'][80:])