text_plain_output_1.png
import pandas as pd

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

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

pop_info = pd.read_csv('../input/population-by-country-2020/population_by_country_2020.csv')

pop_info.rename(columns={'Density (P/Km²)': 'Density'}, inplace=True)

pop_info.columns

country_lookup = pop_info[['Country (or dependency)', 'Population (2020)', 'Density', 'Med. Age', 'Urban Pop %']]

pd.DataFrame.from_dict(country_lookup)
train_df_pop = pd.merge(train_df, country_lookup, how='left', left_on='Country_Region', right_on='Country (or dependency)')

test_df_pop = pd.merge(test_df, country_lookup, how='left', left_on='Country_Region', right_on='Country (or dependency)')

test_df_pop.loc[test_df_pop['Country_Region'] == 'US', ['Population (2020)']] = 331002651
test_df_pop.loc[test_df_pop['Country_Region'] == 'US', ['Density']] = 36
test_df_pop.loc[test_df_pop['Country_Region'] == 'US', ['Med. Age']] = 38
test_df_pop.loc[test_df_pop['Country_Region'] == 'US', ['Urban Pop %']] = '83%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Burma', ['Population (2020)']] = 54409800
test_df_pop.loc[test_df_pop['Country_Region'] == 'Burma', ['Density']] = 83
test_df_pop.loc[test_df_pop['Country_Region'] == 'Burma', ['Med. Age']] = 29
test_df_pop.loc[test_df_pop['Country_Region'] == 'Burma', ['Urban Pop %']] = '39%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Sao Tome and Principe', ['Population (2020)']] = 219159
test_df_pop.loc[test_df_pop['Country_Region'] == 'Sao Tome and Principe', ['Density']] = 228
test_df_pop.loc[test_df_pop['Country_Region'] == 'Sao Tome and Principe', ['Med. Age']] = 19
test_df_pop.loc[test_df_pop['Country_Region'] == 'Sao Tome and Principe', ['Urban Pop %']] = '74%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'West Bank and Gaza', ['Population (2020)']] = 3340143
test_df_pop.loc[test_df_pop['Country_Region'] == 'West Bank and Gaza', ['Density']] = 759
test_df_pop.loc[test_df_pop['Country_Region'] == 'West Bank and Gaza', ['Med. Age']] = 17
test_df_pop.loc[test_df_pop['Country_Region'] == 'West Bank and Gaza', ['Urban Pop %']] = '76%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Kosovo', ['Population (2020)']] = 1810463
test_df_pop.loc[test_df_pop['Country_Region'] == 'Kosovo', ['Density']] = 159
test_df_pop.loc[test_df_pop['Country_Region'] == 'Kosovo', ['Med. Age']] = 29
test_df_pop.loc[test_df_pop['Country_Region'] == 'Kosovo', ['Urban Pop %']] = '55%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Korea, South', ['Population (2020)']] = 51269185
test_df_pop.loc[test_df_pop['Country_Region'] == 'Korea, South', ['Density']] = 527
test_df_pop.loc[test_df_pop['Country_Region'] == 'Korea, South', ['Med. Age']] = 44
test_df_pop.loc[test_df_pop['Country_Region'] == 'Korea, South', ['Urban Pop %']] = '82%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Czechia', ['Population (2020)']] = 10708981
test_df_pop.loc[test_df_pop['Country_Region'] == 'Czechia', ['Density']] = 139
test_df_pop.loc[test_df_pop['Country_Region'] == 'Czechia', ['Med. Age']] = 43
test_df_pop.loc[test_df_pop['Country_Region'] == 'Czechia', ['Urban Pop %']] = '74%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Taiwan*', ['Population (2020)']] = 23816775
test_df_pop.loc[test_df_pop['Country_Region'] == 'Taiwan*', ['Density']] = 673
test_df_pop.loc[test_df_pop['Country_Region'] == 'Taiwan*', ['Med. Age']] = 42
test_df_pop.loc[test_df_pop['Country_Region'] == 'Taiwan*', ['Urban Pop %']] = '79%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Kinshasa)', ['Population (2020)']] = 89561403
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Kinshasa)', ['Density']] = 40
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Kinshasa)', ['Med. Age']] = 17
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Kinshasa)', ['Urban Pop %']] = '46%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Brazzaville)', ['Population (2020)']] = 5518087
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Brazzaville)', ['Density']] = 16
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Brazzaville)', ['Med. Age']] = 19
test_df_pop.loc[test_df_pop['Country_Region'] == 'Congo (Brazzaville)', ['Urban Pop %']] = '70%'
test_df_pop.loc[test_df_pop['Country_Region'] == "Cote d'Ivoire", ['Population (2020)']] = 26378274
test_df_pop.loc[test_df_pop['Country_Region'] == "Cote d'Ivoire", ['Density']] = 83
test_df_pop.loc[test_df_pop['Country_Region'] == "Cote d'Ivoire", ['Med. Age']] = 19
test_df_pop.loc[test_df_pop['Country_Region'] == "Cote d'Ivoire", ['Urban Pop %']] = '51%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Kitts and Nevis', ['Population (2020)']] = 53199
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Kitts and Nevis', ['Density']] = 205
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Kitts and Nevis', ['Med. Age']] = 36
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Kitts and Nevis', ['Urban Pop %']] = '33%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Vincent and the Grenadines', ['Population (2020)']] = 110940
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Vincent and the Grenadines', ['Density']] = 284
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Vincent and the Grenadines', ['Med. Age']] = 33
test_df_pop.loc[test_df_pop['Country_Region'] == 'Saint Vincent and the Grenadines', ['Urban Pop %']] = '53%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'Diamond Princess', ['Population (2020)']] = 3770
test_df_pop.loc[test_df_pop['Country_Region'] == 'Diamond Princess', ['Density']] = 3770
test_df_pop.loc[test_df_pop['Country_Region'] == 'Diamond Princess', ['Med. Age']] = 62
test_df_pop.loc[test_df_pop['Country_Region'] == 'Diamond Princess', ['Urban Pop %']] = '100%'
test_df_pop.loc[test_df_pop['Country_Region'] == 'MS Zaandam', ['Population (2020)']] = 1432
test_df_pop.loc[test_df_pop['Country_Region'] == 'MS Zaandam', ['Density']] = 1432
test_df_pop.loc[test_df_pop['Country_Region'] == 'MS Zaandam', ['Med. Age']] = 65
test_df_pop.loc[test_df_pop['Country_Region'] == 'MS Zaandam', ['Urban Pop %']] = '100%'

test_df_pop.isnull().sum()