Skip to content

Instantly share code, notes, and snippets.

@stucka
Created June 19, 2020 23:29
Show Gist options
  • Save stucka/69fd345390eb5dfd1e663e7b0d54d28e to your computer and use it in GitHub Desktop.
Save stucka/69fd345390eb5dfd1e663e7b0d54d28e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"import csv\n",
"from collections import OrderedDict"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"nationallist = \"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv\"\n",
"countylist = \"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_US.csv\""
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"eulist = [\n",
" \"Austria\",\n",
" \"Belgium\",\n",
" \"Bulgaria\",\n",
" \"Croatia\",\n",
" \"Cyprus\",\n",
" \"Czechia\", # Czech Republic\n",
" \"Denmark\",\n",
" \"Estonia\",\n",
" \"Finland\",\n",
" \"France\",\n",
" \"Germany\",\n",
" \"Greece\",\n",
" \"Hungary\",\n",
" \"Ireland\",\n",
" \"Italy\",\n",
" \"Latvia\",\n",
" \"Lithuania\",\n",
" \"Luxembourg\",\n",
" \"Malta\",\n",
" \"Netherlands\",\n",
" \"Poland\",\n",
" \"Portugal\",\n",
" \"Romania\",\n",
" \"Slovakia\",\n",
" \"Slovenia\",\n",
" \"Spain\",\n",
" \"Sweden\" \n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(nationallist)\n",
"reader = list(csv.DictReader(r.text.splitlines()))\n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"headers = list(reader[0].keys())\n",
"mydates = headers[headers.index(\"1/22/20\"):]"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"nationdict = OrderedDict()\n",
"eutallied = []\n",
"nationdict['European Union'] = OrderedDict()\n",
"for mydate in mydates:\n",
" nationdict['European Union'][mydate] = 0\n",
"for row in reader:\n",
" nation = row['Country/Region']\n",
" if nation not in nationdict:\n",
" nationdict[nation] = OrderedDict()\n",
" for mydate in mydates:\n",
" nationdict[nation][mydate] = 0\n",
" for mydate in mydates:\n",
" nationdict[nation][mydate] += int(row[mydate])\n",
" if nation in eulist:\n",
" for mydate in mydates:\n",
" nationdict[\"European Union\"][mydate] += int(row[mydate])\n",
" eutally += 1\n",
" eutallied.append(nation)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"eutallied = set(eutallied)\n",
"for nation in eulist:\n",
" if nation not in eutallied:\n",
" print(nation)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5745"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nationdict['European Union'][\"6/18/20\"] - nationdict['European Union'][\"6/17/20\"]"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(countylist)\n",
"reader = list(csv.DictReader(r.text.splitlines()))"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"statedict = OrderedDict()\n",
"for row in reader:\n",
" state = row['Province_State']\n",
" if state not in statedict:\n",
" statedict[state] = OrderedDict()\n",
" for mydate in mydates:\n",
" statedict[state][mydate] = 0\n",
" for mydate in mydates:\n",
" statedict[state][mydate] += int(row[mydate])"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"85926"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"statedict['Florida']['6/18/20']"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"reader = None"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"nationdiff = OrderedDict()\n",
"for nation in nationdict:\n",
" nationdiff[nation] = OrderedDict()\n",
" for i, mydate in enumerate(mydates[:-7]):\n",
" # print(f\"{mydates[i]} ... {mydates[i+7]}\")\n",
" nationdiff[nation][mydates[i+7]] = nationdict[nation][mydates[i+7]] - nationdict[nation][mydates[i]]"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"statediff = OrderedDict()\n",
"for state in statedict:\n",
" statediff[state] = OrderedDict()\n",
" for i, mydate in enumerate(mydates[:-7]):\n",
" statediff[state][mydates[i+7]] = statedict[state][mydates[i+7]] - statedict[state][mydates[i]]"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('1/29/20', 0),\n",
" ('1/30/20', 0),\n",
" ('1/31/20', 0),\n",
" ('2/1/20', 0),\n",
" ('2/2/20', 0),\n",
" ('2/3/20', 0),\n",
" ('2/4/20', 0),\n",
" ('2/5/20', 0),\n",
" ('2/6/20', 0),\n",
" ('2/7/20', 0),\n",
" ('2/8/20', 0),\n",
" ('2/9/20', 0),\n",
" ('2/10/20', 0),\n",
" ('2/11/20', 0),\n",
" ('2/12/20', 0),\n",
" ('2/13/20', 0),\n",
" ('2/14/20', 0),\n",
" ('2/15/20', 0),\n",
" ('2/16/20', 0),\n",
" ('2/17/20', 0),\n",
" ('2/18/20', 0),\n",
" ('2/19/20', 0),\n",
" ('2/20/20', 0),\n",
" ('2/21/20', 0),\n",
" ('2/22/20', 0),\n",
" ('2/23/20', 0),\n",
" ('2/24/20', 0),\n",
" ('2/25/20', 0),\n",
" ('2/26/20', 0),\n",
" ('2/27/20', 0),\n",
" ('2/28/20', 0),\n",
" ('2/29/20', 0),\n",
" ('3/1/20', 0),\n",
" ('3/2/20', 1),\n",
" ('3/3/20', 2),\n",
" ('3/4/20', 2),\n",
" ('3/5/20', 3),\n",
" ('3/6/20', 3),\n",
" ('3/7/20', 7),\n",
" ('3/8/20', 10),\n",
" ('3/9/20', 12),\n",
" ('3/10/20', 13),\n",
" ('3/11/20', 22),\n",
" ('3/12/20', 27),\n",
" ('3/13/20', 47),\n",
" ('3/14/20', 69),\n",
" ('3/15/20', 90),\n",
" ('3/16/20', 88),\n",
" ('3/17/20', 175),\n",
" ('3/18/20', 282),\n",
" ('3/19/20', 402),\n",
" ('3/20/20', 514),\n",
" ('3/21/20', 687),\n",
" ('3/22/20', 904),\n",
" ('3/23/20', 1126),\n",
" ('3/24/20', 1222),\n",
" ('3/25/20', 1376),\n",
" ('3/26/20', 1925),\n",
" ('3/27/20', 2336),\n",
" ('3/28/20', 3000),\n",
" ('3/29/20', 3242),\n",
" ('3/30/20', 4246),\n",
" ('3/31/20', 5329),\n",
" ('4/1/20', 5274),\n",
" ('4/2/20', 6651),\n",
" ('4/3/20', 7368),\n",
" ('4/4/20', 7774),\n",
" ('4/5/20', 8104),\n",
" ('4/6/20', 7851),\n",
" ('4/7/20', 7804),\n",
" ('4/8/20', 8500),\n",
" ('4/9/20', 7356),\n",
" ('4/10/20', 7263),\n",
" ('4/11/20', 6957),\n",
" ('4/12/20', 7545),\n",
" ('4/13/20', 7695),\n",
" ('4/14/20', 7083),\n",
" ('4/15/20', 7055),\n",
" ('4/16/20', 6979),\n",
" ('4/17/20', 7228),\n",
" ('4/18/20', 6998),\n",
" ('4/19/20', 6419),\n",
" ('4/20/20', 6040),\n",
" ('4/21/20', 6241),\n",
" ('4/22/20', 5798),\n",
" ('4/23/20', 6305),\n",
" ('4/24/20', 5774),\n",
" ('4/25/20', 5347),\n",
" ('4/26/20', 5218),\n",
" ('4/27/20', 5079),\n",
" ('4/28/20', 4979),\n",
" ('4/29/20', 4884),\n",
" ('4/30/20', 4042),\n",
" ('5/1/20', 4195),\n",
" ('5/2/20', 4624),\n",
" ('5/3/20', 4546),\n",
" ('5/4/20', 4759),\n",
" ('5/5/20', 4591),\n",
" ('5/6/20', 4809),\n",
" ('5/7/20', 5138),\n",
" ('5/8/20', 4471),\n",
" ('5/9/20', 4538),\n",
" ('5/10/20', 4518),\n",
" ('5/11/20', 4085),\n",
" ('5/12/20', 4484),\n",
" ('5/13/20', 4400),\n",
" ('5/14/20', 4382),\n",
" ('5/15/20', 4939),\n",
" ('5/16/20', 4810),\n",
" ('5/17/20', 4992),\n",
" ('5/18/20', 5460),\n",
" ('5/19/20', 5021),\n",
" ('5/20/20', 5069),\n",
" ('5/21/20', 5465),\n",
" ('5/22/20', 5313),\n",
" ('5/23/20', 5316),\n",
" ('5/24/20', 5279),\n",
" ('5/25/20', 5304),\n",
" ('5/26/20', 5311),\n",
" ('5/27/20', 5163),\n",
" ('5/28/20', 4610),\n",
" ('5/29/20', 5046),\n",
" ('5/30/20', 5297),\n",
" ('5/31/20', 5296),\n",
" ('6/1/20', 5084),\n",
" ('6/2/20', 5192),\n",
" ('6/3/20', 6130),\n",
" ('6/4/20', 6898),\n",
" ('6/5/20', 6991),\n",
" ('6/6/20', 7334),\n",
" ('6/7/20', 7775),\n",
" ('6/8/20', 8074),\n",
" ('6/9/20', 8553),\n",
" ('6/10/20', 8607),\n",
" ('6/11/20', 8886),\n",
" ('6/12/20', 9483),\n",
" ('6/13/20', 10794),\n",
" ('6/14/20', 11630),\n",
" ('6/15/20', 12422),\n",
" ('6/16/20', 14109),\n",
" ('6/17/20', 15348),\n",
" ('6/18/20', 16857)])"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"statediff['Florida']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment