text_html_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import os

import pandas as pd

np.random.seed(2019)
os.environ['PYTHONHASHSEED'] = '2019'
plt.style.use('seaborn-ticks')
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams['font.size'] = 11.0
plt.rcParams['figure.figsize'] = (9, 6)
pd.set_option('display.max_colwidth', 1000)

population_raw = pd.read_csv('/kaggle/input/covid19-global-forecasting-locations-population/locations_population.csv')

pd.DataFrame(population_raw.isnull().sum()).T

df = population_raw.copy()
df = df.rename({'Province.State': 'Province', 'Country.Region': 'Country'}, axis=1)
cols = ['Country', 'Province', 'Population']
df = df.loc[:, cols].fillna('-')
df.loc[df['Country'] == df['Province'], 'Province'] = '-'
_total_df = df.loc[df['Province'] != '-', :].groupby('Country').sum()
_total_df = _total_df.reset_index().assign(Province='-')
df = pd.concat([df, _total_df], axis=0, sort=True)
df = df.drop_duplicates(subset=['Country', 'Province'], keep='first')
global_value = df.loc[df['Province'] == '-', 'Population'].sum()
df = df.append(pd.Series(['Global', '-', global_value], index=cols), ignore_index=True)
df = df.sort_values('Population', ascending=False).reset_index(drop=True)
df = df.loc[:, cols]
population_df = df.copy()

df = population_df.loc[population_df['Province'] == '-', :]
population_dict = df.set_index('Country').to_dict()['Population']
population_dict