Skip to content
Snippets Groups Projects
Commit 53174ee1 authored by Chandrasekhar Ramakrishnan's avatar Chandrasekhar Ramakrishnan
Browse files

feat: work on the play notebook

parent e8d09f63
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import pandas as pd
```
%% Cell type:markdown id: tags:
# Read in JHU CSSE data
I will switch to [xarray](http://xarray.pydata.org/en/stable/), but ATM, it's easier like this...
%% Cell type:code id: tags:
``` python
def read_jhu_covid_df(name):
filename = f"../data/covid-19_jhu-csse/time_series_19-covid-{name}.csv"
df = pd.read_csv(filename)
df = df.set_index(['Province/State', 'Country/Region', 'Lat', 'Long'])
df.columns = pd.to_datetime(df.columns)
return df
```
%% Cell type:code id: tags:
``` python
confirmed_df = read_jhu_covid_df("Confirmed")
deaths_df = read_jhu_covid_df("Deaths")
recovered_df = read_jhu_covid_df("Recovered")
frames_map = {
"confirmed": read_jhu_covid_df("Confirmed"),
"deaths": read_jhu_covid_df("Deaths"),
"recovered": read_jhu_covid_df("Recovered")
}
```
%% Cell type:code id: tags:
``` python
def summarize_df(df, name):
ser = df.groupby(level='Country/Region').sum().iloc[:,-1].sort_values(ascending=False)
ser.name = f"Total {name}"
return ser
def current_region_totals_df(frames_map):
sers = [df.groupby(level='Country/Region').sum().iloc[:,-1].sort_values(ascending=False)
for name, df in frames_map.items()]
for name, ser in zip(frames_map, sers):
ser.name = name
return pd.concat(sers, axis=1)
```
%% Cell type:code id: tags:
``` python
confirmed_ser = summarize_df(confirmed_df, "Confirmed")
deaths_ser = summarize_df(deaths_df, "Deaths")
recovered_ser = summarize_df(recovered_df, "Recovered")
current_totals_df = current_region_totals_df(frames_map)
current_totals_df[current_totals_df['confirmed'] > 100]
```
%% Output
confirmed deaths recovered
Mainland China 80757 3136 60106
Italy 10149 631 724
Iran (Islamic Republic of) 8042 291 2731
Republic of Korea 7513 54 247
France 1784 33 12
Spain 1695 35 32
US 1670 56 15
Germany 1457 2 18
Others 696 6 40
Japan 581 10 101
Switzerland 491 3 3
Norway 400 0 1
UK 382 6 18
Netherlands 382 4 0
Sweden 355 0 1
Belgium 267 0 1
Denmark 262 0 1
Austria 182 0 4
Singapore 160 0 78
Malaysia 129 0 24
Hong Kong SAR 120 3 65
Bahrain 110 0 22
Australia 107 3 21
%% Cell type:markdown id: tags:
# Read in World Bank data
%% Cell type:code id: tags:
``` python
import zipfile
zf = zipfile.ZipFile("../data/worldbank/SP.POP.TOTL.zip")
pop_df = pd.read_csv(zf.open("API_SP.POP.TOTL_DS2_en_csv_v2_821007.csv"), skiprows=4)
```
%% Cell type:code id: tags:
``` python
# There is 2018 pop data for all countries/regions except Eritrea
pop_df[pd.isna(pop_df['2018'])]
```
%% Output
Country Name Country Code Indicator Name Indicator Code 1960 \
67 Eritrea ERI Population, total SP.POP.TOTL 1007590.0
108 Not classified INX Population, total SP.POP.TOTL NaN
1961 1962 1963 1964 1965 ... 2011 \
67 1033328.0 1060486.0 1088854.0 1118159.0 1148189.0 ... 3213972.0
108 NaN NaN NaN NaN NaN ... NaN
2012 2013 2014 2015 2016 2017 2018 2019 Unnamed: 64
67 NaN NaN NaN NaN NaN NaN NaN NaN NaN
108 NaN NaN NaN NaN NaN NaN NaN NaN NaN
[2 rows x 65 columns]
%% Cell type:markdown id: tags:
Fix the country/region names that differ
%% Cell type:code id: tags:
``` python
region_wb_jhu_map = {
'China': 'Mainland China',
'Iran, Islamic Rep.': 'Iran (Islamic Republic of)',
'Korea, Rep.': 'Republic of Korea',
'United States': 'US',
'United Kingdom': 'UK',
'Hong Kong SAR, China': 'Hong Kong SAR',
'Egypt, Arab Rep.': 'Egypt',
'Vietnam': 'Viet Nam',
'Macao SAR, China': 'Macao SAR',
'Slovak Republic': 'Slovakia',
'Moldova': 'Republic of Moldova',
'St. Martin (French part)': 'Saint Martin',
'Brunei Darussalam': 'Brunei'
}
current_pop_ser = pop_df[['Country Name', '2018']].copy().replace(region_wb_jhu_map).set_index('Country Name')
data_pop_ser = current_pop_ser[current_pop_ser.index.isin(current_totals_df.index)]
```
%% Cell type:markdown id: tags:
There are some regions that we cannot resolve, but we will just ignore these.
%% Cell type:code id: tags:
``` python
current_totals_df[current_totals_df.index.isin(data_pop_ser.index) == False]
```
%% Output
confirmed deaths recovered
Others 696 6 40
Taipei and environs 47 1 17
occupied Palestinian territory 25 0 0
French Guiana 5 0 0
Martinique 2 0 0
Holy See 1 0 0
Saint Barthelemy 1 0 0
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment