image_output_11.png text_plain_output_5.png text_plain_output_9.png image_output_14.png text_plain_output_4.png text_plain_output_13.png image_output_13.png image_output_5.png text_plain_output_14.png text_plain_output_10.png text_plain_output_6.png image_output_7.png text_plain_output_3.png image_output_4.png text_plain_output_7.png image_output_8.png text_plain_output_8.png image_output_6.png image_output_12.png text_plain_output_2.png text_plain_output_1.png image_output_3.png image_output_2.png image_output_1.png image_output_10.png text_plain_output_11.png text_plain_output_12.png image_output_9.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd

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

submission = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv')
test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
train['Province_State'].fillna('', inplace=True)
train['Date'] = pd.to_datetime(train['Date'])
train['day'] = train.Date.dt.dayofyear
train['geo'] = ['_'.join(x) for x in zip(train['Country_Region'], train['Province_State'])]
test['Province_State'].fillna('', inplace=True)
test['Date'] = pd.to_datetime(test['Date'])
test['day'] = test.Date.dt.dayofyear
test['geo'] = ['_'.join(x) for x in zip(test['Country_Region'], test['Province_State'])]
train.sort_values(by='Date', inplace=True)
test.sort_values(by='Date', inplace=True)
day_min = train['day'].min()
train['day'] -= day_min
test['day'] -= day_min
test['ConfirmedCases'] = np.nan
test['Fatalities'] = np.nan
train['ForecastId'] = np.nan
test['Id'] = np.nan
min_date_train = train['Date'].min()
min_date_test = test['Date'].min()
max_date_train = train['Date'].max()
max_date_test = test['Date'].max()
num_of_days_train = (max_date_train - min_date_train) / np.timedelta64(1, 'D') + 1
num_of_days = int((max_date_test - min_date_train) / np.timedelta64(1, 'D')) + 1
time_span0 = pd.date_range(min_date_train, max_date_test)
time_span = [str(s.month) + '/' + str(s.day) for s in time_span0]
forcast_days = int((max_date_test - max_date_train) / np.timedelta64(1, 'D'))

countries = dict()
for cnt in train['Country_Region'].unique():
    countries[cnt] = train.loc[train['Country_Region'] == cnt, 'Province_State'].unique()
countries_test = dict()
for cnt in test['Country_Region'].unique():
    countries_test[cnt] = test.loc[test['Country_Region'] == cnt, 'Province_State'].unique()

res = []
for country in countries:
    for state in countries[country]:
        if country != 'China':
            country_state_filter_train = (train['Province_State'] == state) & (train['Country_Region'] == country)
            sliced_data = train.loc[country_state_filter_train, :]
            history = sliced_data.loc[sliced_data['ConfirmedCases'] > 0, 'ConfirmedCases'].to_list()
            res.append(num_of_days_train - len(history))
aa = plt.figure()
aa = plt.hist(res, color='blue', bins=10, range=(0, 80))
aa = plt.title('first Confirmed Case histogram: # of countries/provinces(except China) .VS. days from Wuhan Lockdown(1/22/2020)')
res = []
for country in countries:
    for state in countries[country]:
        if country != 'China':
            country_state_filter_train = (train['Province_State'] == state) & (train['Country_Region'] == country)
            sliced_data = train.loc[country_state_filter_train, :]
            history = sliced_data.loc[sliced_data['Fatalities'] > 0, 'Fatalities'].to_list()
            res.append(num_of_days_train - len(history))
aa = plt.figure()
aa = plt.hist(res, color='red', bins=10, range=(0, 80))
aa = plt.title('first death histogram: # of countries/provinces(except China) .VS. days from Wuhan Lockdown(1/22/2020)')