text_html_output_1.png
import numpy as np

import pandas as pd

import os, gc, pickle, copy, datetime, warnings
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import lightgbm as lgb
from sklearn import metrics
pd.set_option('display.max_columns', 100)
warnings.filterwarnings('ignore')

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

df_test = pd.read_csv('../input/covid19-global-forecasting-week-4/test.csv')

df_traintest = pd.concat([df_train, df_test])

df_traintest['Date'] = pd.to_datetime(df_traintest['Date'])
df_traintest['day'] = df_traintest['Date'].apply(lambda x: x.dayofyear).astype(np.int16)

day_before_valid = 71 + 7 + 7
day_before_public = 78 + 7 + 7
day_before_private = df_traintest['day'][pd.isna(df_traintest['ForecastId'])].max()

def func(x):
    try:
        x_new = x['Country_Region'] + '/' + x['Province_State']
    except:
        x_new = x['Country_Region']
    return x_new
df_traintest['place_id'] = df_traintest.apply(lambda x: func(x), axis=1)

df_latlong = pd.read_csv('../input/smokingstats/df_Latlong.csv')

def func(x):
    try:
        x_new = x['Country/Region'] + '/' + x['Province/State']
    except:
        x_new = x['Country/Region']
    return x_new
df_latlong['place_id'] = df_latlong.apply(lambda x: func(x), axis=1)
df_latlong = df_latlong[df_latlong['place_id'].duplicated() == False]

df_traintest = pd.merge(df_traintest, df_latlong[['place_id', 'Lat', 'Long']], on='place_id', how='left')

places = np.sort(df_traintest['place_id'].unique())

df_traintest2 = copy.deepcopy(df_traintest)
df_traintest2['cases/day'] = 0
df_traintest2['fatal/day'] = 0
tmp_list = np.zeros(len(df_traintest2))
for place in places:
    tmp = df_traintest2['ConfirmedCases'][df_traintest2['place_id'] == place].values
    tmp[1:] -= tmp[:-1]
    df_traintest2['cases/day'][df_traintest2['place_id'] == place] = tmp
    tmp = df_traintest2['Fatalities'][df_traintest2['place_id'] == place].values
    tmp[1:] -= tmp[:-1]
    df_traintest2['fatal/day'][df_traintest2['place_id'] == place] = tmp
print(df_traintest2.shape)
df_traintest2[df_traintest2['place_id'] == 'China/Hubei'].head()