text_plain_output_1.png
import numpy as np

import numpy as np

import pandas as pd

import pandas as pd

import warnings

import pandas as pd
import numpy as np
import gc
import warnings
warnings.filterwarnings('ignore')
train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
train.rename(columns={'Country_Region': 'Country', 'Province_State': 'State', 'ConfirmedCases': 'Confirmed'}, inplace=True)
test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
test.rename(columns={'Country_Region': 'Country', 'Province_State': 'State', 'ConfirmedCases': 'Confirmed', 'ForecastId': 'Id'}, inplace=True)
train['Type'] = 'train'
test['Type'] = 'test'
test['Confirmed'] = 0
test['Fatalities'] = 0

import pandas as pd
import numpy as np
import os, gc
train['id_x'] = train['Date'].astype(str).values + '_' + train['State'].astype(str).values + '_' + train['Country'].astype(str).values + '_' + train['Type'].astype(str).values
test['id_x'] = test['Date'].astype(str).values + '_' + test['State'].astype(str).values + '_' + test['Country'].astype(str).values + '_' + test['Type'].astype(str).values
raw = pd.concat([train, test], axis=0, sort=False)
raw['Date'] = pd.to_datetime(raw['Date'])
raw.sort_values('Date', inplace=True)
raw.fillna(0, inplace=True)
Country_State = raw.Country + '_' + raw.State.astype(str)
raw['Country_State_id'] = Country_State.astype('category').cat.codes
raw['Day'] = raw['Date'].astype('category').cat.codes + 1
raw.set_index('Country_State_id', inplace=True)
raw.Day = raw.Day.astype(np.int32)
raw.reset_index(inplace=True)
features = ['id_x', 'Day', 'Id', 'Country_State_id']
train = train.merge(raw[features], on=['id_x'], how='left')
test = test.merge(raw[features], on=['id_x'], how='left')
print(train.shape, test.shape)