Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
covid-19-public-data
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simon Duerr
covid-19-public-data
Commits
e8d09f63
Commit
e8d09f63
authored
5 years ago
by
Chandrasekhar Ramakrishnan
Browse files
Options
Downloads
Patches
Plain Diff
feat: notebook for playing with data
parent
f6f887b1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
notebooks/Play.ipynb
+109
-0
109 additions, 0 deletions
notebooks/Play.ipynb
with
109 additions
and
0 deletions
notebooks/Play.ipynb
0 → 100644
+
109
−
0
View file @
e8d09f63
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Read in JHU CSSE data\n",
"\n",
"I will switch to [xarray](http://xarray.pydata.org/en/stable/), but ATM, it's easier like this..."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def read_jhu_covid_df(name):\n",
" filename = f\"../data/covid-19_jhu-csse/time_series_19-covid-{name}.csv\"\n",
" df = pd.read_csv(filename)\n",
" df = df.set_index(['Province/State', 'Country/Region', 'Lat', 'Long'])\n",
" df.columns = pd.to_datetime(df.columns)\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"confirmed_df = read_jhu_covid_df(\"Confirmed\")\n",
"deaths_df = read_jhu_covid_df(\"Deaths\")\n",
"recovered_df = read_jhu_covid_df(\"Recovered\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"def summarize_df(df, name):\n",
" ser = df.groupby(level='Country/Region').sum().iloc[:,-1].sort_values(ascending=False)\n",
" ser.name = f\"Total {name}\"\n",
" return ser"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"confirmed_ser = summarize_df(confirmed_df, \"Confirmed\")\n",
"deaths_ser = summarize_df(deaths_df, \"Deaths\")\n",
"recovered_ser = summarize_df(recovered_df, \"Recovered\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Read in World Bank data"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"import zipfile\n",
"zf = zipfile.ZipFile(\"../data/worldbank/SP.POP.TOTL.zip\")\n",
"pop_df = pd.read_csv(zf.open(\"API_SP.POP.TOTL_DS2_en_csv_v2_821007.csv\"), skiprows=4)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% 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
"
)
```
%% 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
```
%% 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
"
)
```
%% 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
)
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment