{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Covid 19"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Active reporting on COVID-19 deaths will drastically improve civil and government measures. We will pull COVID-19 data and build an interactive nation wide map broken down by state and age group."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Steps**\n",
"\n",
"**1. Import Libraries**\n",
"**2. Process Data**\n",
"**3. Map Data**\n",
"**4. Feedback**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" CDC Data "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://data.cdc.gov/NCHS/Provisional-COVID-19-Death-Counts-by-Sex-Age-and-S/9bhg-hcku"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting package metadata (current_repodata.json): done\n",
"Solving environment: done\n",
"\n",
"## Package Plan ##\n",
"\n",
" environment location: /home/jupyterlab/conda/envs/python\n",
"\n",
" added / updated specs:\n",
" - geopy\n",
"\n",
"\n",
"The following packages will be downloaded:\n",
"\n",
" package | build\n",
" ---------------------------|-----------------\n",
" ca-certificates-2020.4.5.2 | hecda079_0 147 KB conda-forge\n",
" certifi-2020.4.5.2 | py36h9f0ad1d_0 152 KB conda-forge\n",
" geographiclib-1.50 | py_0 34 KB conda-forge\n",
" geopy-1.22.0 | pyh9f0ad1d_0 63 KB conda-forge\n",
" ------------------------------------------------------------\n",
" Total: 395 KB\n",
"\n",
"The following NEW packages will be INSTALLED:\n",
"\n",
" geographiclib conda-forge/noarch::geographiclib-1.50-py_0\n",
" geopy conda-forge/noarch::geopy-1.22.0-pyh9f0ad1d_0\n",
"\n",
"The following packages will be UPDATED:\n",
"\n",
" ca-certificates 2020.4.5.1-hecc5488_0 --> 2020.4.5.2-hecda079_0\n",
" certifi 2020.4.5.1-py36h9f0ad1d_0 --> 2020.4.5.2-py36h9f0ad1d_0\n",
"\n",
"\n",
"\n",
"Downloading and Extracting Packages\n",
"geopy-1.22.0 | 63 KB | ##################################### | 100% \n",
"certifi-2020.4.5.2 | 152 KB | ##################################### | 100% \n",
"ca-certificates-2020 | 147 KB | ##################################### | 100% \n",
"geographiclib-1.50 | 34 KB | ##################################### | 100% \n",
"Preparing transaction: done\n",
"Verifying transaction: done\n",
"Executing transaction: done\n",
"Collecting package metadata (current_repodata.json): done\n",
"Solving environment: failed with initial frozen solve. Retrying with flexible solve.\n",
"Collecting package metadata (repodata.json): done\n",
"Solving environment: done\n",
"\n",
"## Package Plan ##\n",
"\n",
" environment location: /home/jupyterlab/conda/envs/python\n",
"\n",
" added / updated specs:\n",
" - folium=0.5.0\n",
"\n",
"\n",
"The following packages will be downloaded:\n",
"\n",
" package | build\n",
" ---------------------------|-----------------\n",
" altair-4.1.0 | py_1 614 KB conda-forge\n",
" branca-0.4.1 | py_0 26 KB conda-forge\n",
" brotlipy-0.7.0 |py36h8c4c3a4_1000 346 KB conda-forge\n",
" chardet-3.0.4 |py36h9f0ad1d_1006 188 KB conda-forge\n",
" cryptography-2.9.2 | py36h45558ae_0 613 KB conda-forge\n",
" folium-0.5.0 | py_0 45 KB conda-forge\n",
" pandas-1.0.4 | py36h830a2c2_0 10.1 MB conda-forge\n",
" pysocks-1.7.1 | py36h9f0ad1d_1 27 KB conda-forge\n",
" toolz-0.10.0 | py_0 46 KB conda-forge\n",
" vincent-0.4.4 | py_1 28 KB conda-forge\n",
" ------------------------------------------------------------\n",
" Total: 12.0 MB\n",
"\n",
"The following NEW packages will be INSTALLED:\n",
"\n",
" altair conda-forge/noarch::altair-4.1.0-py_1\n",
" attrs conda-forge/noarch::attrs-19.3.0-py_0\n",
" branca conda-forge/noarch::branca-0.4.1-py_0\n",
" brotlipy conda-forge/linux-64::brotlipy-0.7.0-py36h8c4c3a4_1000\n",
" chardet conda-forge/linux-64::chardet-3.0.4-py36h9f0ad1d_1006\n",
" cryptography conda-forge/linux-64::cryptography-2.9.2-py36h45558ae_0\n",
" entrypoints conda-forge/linux-64::entrypoints-0.3-py36h9f0ad1d_1001\n",
" folium conda-forge/noarch::folium-0.5.0-py_0\n",
" idna conda-forge/noarch::idna-2.9-py_1\n",
" importlib_metadata conda-forge/noarch::importlib_metadata-1.6.0-0\n",
" jinja2 conda-forge/noarch::jinja2-2.11.2-pyh9f0ad1d_0\n",
" jsonschema conda-forge/linux-64::jsonschema-3.2.0-py36h9f0ad1d_1\n",
" markupsafe conda-forge/linux-64::markupsafe-1.1.1-py36h8c4c3a4_1\n",
" pandas conda-forge/linux-64::pandas-1.0.4-py36h830a2c2_0\n",
" pyopenssl conda-forge/noarch::pyopenssl-19.1.0-py_1\n",
" pyrsistent conda-forge/linux-64::pyrsistent-0.16.0-py36h8c4c3a4_0\n",
" pysocks conda-forge/linux-64::pysocks-1.7.1-py36h9f0ad1d_1\n",
" pytz conda-forge/noarch::pytz-2020.1-pyh9f0ad1d_0\n",
" requests conda-forge/noarch::requests-2.23.0-pyh8c360ce_2\n",
" toolz conda-forge/noarch::toolz-0.10.0-py_0\n",
" urllib3 conda-forge/noarch::urllib3-1.25.9-py_0\n",
" vincent conda-forge/noarch::vincent-0.4.4-py_1\n",
"\n",
"\n",
"\n",
"Downloading and Extracting Packages\n",
"pysocks-1.7.1 | 27 KB | ##################################### | 100% \n",
"toolz-0.10.0 | 46 KB | ##################################### | 100% \n",
"chardet-3.0.4 | 188 KB | ##################################### | 100% \n",
"pandas-1.0.4 | 10.1 MB | ##################################### | 100% \n",
"folium-0.5.0 | 45 KB | ##################################### | 100% \n",
"branca-0.4.1 | 26 KB | ##################################### | 100% \n",
"cryptography-2.9.2 | 613 KB | ##################################### | 100% \n",
"brotlipy-0.7.0 | 346 KB | ##################################### | 100% \n",
"altair-4.1.0 | 614 KB | ##################################### | 100% \n",
"vincent-0.4.4 | 28 KB | ##################################### | 100% \n",
"Preparing transaction: done\n",
"Verifying transaction: done\n",
"Executing transaction: done\n",
"Collecting lxml\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/55/6f/c87dffdd88a54dd26a3a9fef1d14b6384a9933c455c54ce3ca7d64a84c88/lxml-4.5.1-cp36-cp36m-manylinux1_x86_64.whl (5.5MB)\n",
"\u001b[K |████████████████████████████████| 5.5MB 4.9MB/s eta 0:00:01 |████████████████▊ | 2.9MB 4.9MB/s eta 0:00:01\n",
"\u001b[?25hInstalling collected packages: lxml\n",
"Successfully installed lxml-4.5.1\n",
"Collecting beautifulsoup4\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/66/25/ff030e2437265616a1e9b25ccc864e0371a0bc3adb7c5a404fd661c6f4f6/beautifulsoup4-4.9.1-py3-none-any.whl (115kB)\n",
"\u001b[K |████████████████████████████████| 122kB 5.2MB/s eta 0:00:01\n",
"\u001b[?25hCollecting soupsieve>1.2 (from beautifulsoup4)\n",
" Downloading https://files.pythonhosted.org/packages/6f/8f/457f4a5390eeae1cc3aeab89deb7724c965be841ffca6cfca9197482e470/soupsieve-2.0.1-py3-none-any.whl\n",
"Installing collected packages: soupsieve, beautifulsoup4\n",
"Successfully installed beautifulsoup4-4.9.1 soupsieve-2.0.1\n",
"Collecting geocoder\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/4f/6b/13166c909ad2f2d76b929a4227c952630ebaf0d729f6317eb09cbceccbab/geocoder-1.38.1-py2.py3-none-any.whl (98kB)\n",
"\u001b[K |████████████████████████████████| 102kB 6.4MB/s ta 0:00:011\n",
"\u001b[?25hCollecting click (from geocoder)\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB)\n",
"\u001b[K |████████████████████████████████| 92kB 5.8MB/s eta 0:00:01\n",
"\u001b[?25hRequirement already satisfied: requests in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from geocoder) (2.23.0)\n",
"Collecting ratelim (from geocoder)\n",
" Downloading https://files.pythonhosted.org/packages/f2/98/7e6d147fd16a10a5f821db6e25f192265d6ecca3d82957a4fdd592cad49c/ratelim-0.1.6-py2.py3-none-any.whl\n",
"Requirement already satisfied: six in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from geocoder) (1.14.0)\n",
"Collecting future (from geocoder)\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz (829kB)\n",
"\u001b[K |████████████████████████████████| 829kB 26.0MB/s eta 0:00:01\n",
"\u001b[?25hRequirement already satisfied: chardet<4,>=3.0.2 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from requests->geocoder) (3.0.4)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from requests->geocoder) (1.25.9)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from requests->geocoder) (2020.4.5.2)\n",
"Requirement already satisfied: idna<3,>=2.5 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from requests->geocoder) (2.9)\n",
"Requirement already satisfied: decorator in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ratelim->geocoder) (4.4.2)\n",
"Building wheels for collected packages: future\n",
" Building wheel for future (setup.py) ... \u001b[?25ldone\n",
"\u001b[?25h Stored in directory: /home/jupyterlab/.cache/pip/wheels/8b/99/a0/81daf51dcd359a9377b110a8a886b3895921802d2fc1b2397e\n",
"Successfully built future\n",
"Installing collected packages: click, ratelim, future, geocoder\n",
"Successfully installed click-7.1.2 future-0.18.2 geocoder-1.38.1 ratelim-0.1.6\n"
]
}
],
"source": [
"import numpy as np \n",
"import pandas as pd \n",
"import requests \n",
"import folium\n",
"!conda install -c conda-forge geopy --yes\n",
"!conda install -c conda-forge folium=0.5.0 --yes\n",
"from geopy.geocoders import Nominatim \n",
"pd.set_option('display.max_columns', None)\n",
"pd.set_option('display.max_rows', None)\n",
"!pip install lxml\n",
"!pip install beautifulsoup4\n",
"!pip install geocoder"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pull the Data, check it out."
]
},
{
"cell_type": "code",
"execution_count": 145,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Data as of object\n",
"Start week object\n",
"End Week object\n",
"State object\n",
"Sex object\n",
"Age group object\n",
"COVID-19 Deaths float64\n",
"Total Deaths float64\n",
"Pneumonia Deaths float64\n",
"Pneumonia and COVID-19 Deaths float64\n",
"Influenza Deaths float64\n",
"Pneumonia, Influenza, or COVID-19 Deaths float64\n",
"Footnote object\n",
"dtype: object"
]
},
"execution_count": 145,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv('https://data.cdc.gov/api/views/9bhg-hcku/rows.csv?accessType=DOWNLOAD')\n",
"df.dtypes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Trim Data"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" State | \n",
" Deaths | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" AL | \n",
" 638.0 | \n",
"
\n",
" \n",
" 1 | \n",
" AK | \n",
" 0.0 | \n",
"
\n",
" \n",
" 2 | \n",
" AZ | \n",
" 799.0 | \n",
"
\n",
" \n",
" 3 | \n",
" AR | \n",
" 82.0 | \n",
"
\n",
" \n",
" 4 | \n",
" CA | \n",
" 3793.0 | \n",
"
\n",
" \n",
" 5 | \n",
" CO | \n",
" 1310.0 | \n",
"
\n",
" \n",
" 6 | \n",
" CT | \n",
" 2155.0 | \n",
"
\n",
" \n",
" 7 | \n",
" DE | \n",
" 346.0 | \n",
"
\n",
" \n",
" 8 | \n",
" DC | \n",
" 373.0 | \n",
"
\n",
" \n",
" 9 | \n",
" FL | \n",
" 2297.0 | \n",
"
\n",
" \n",
" 10 | \n",
" GA | \n",
" 1608.0 | \n",
"
\n",
" \n",
" 11 | \n",
" HI | \n",
" 0.0 | \n",
"
\n",
" \n",
" 12 | \n",
" ID | \n",
" 65.0 | \n",
"
\n",
" \n",
" 13 | \n",
" IL | \n",
" 4682.0 | \n",
"
\n",
" \n",
" 14 | \n",
" IN | \n",
" 1851.0 | \n",
"
\n",
" \n",
" 15 | \n",
" IA | \n",
" 464.0 | \n",
"
\n",
" \n",
" 16 | \n",
" KS | \n",
" 182.0 | \n",
"
\n",
" \n",
" 17 | \n",
" KY | \n",
" 366.0 | \n",
"
\n",
" \n",
" 18 | \n",
" LA | \n",
" 2191.0 | \n",
"
\n",
" \n",
" 19 | \n",
" ME | \n",
" 79.0 | \n",
"
\n",
" \n",
" 20 | \n",
" MD | \n",
" 2565.0 | \n",
"
\n",
" \n",
" 21 | \n",
" MA | \n",
" 6490.0 | \n",
"
\n",
" \n",
" 22 | \n",
" MI | \n",
" 4616.0 | \n",
"
\n",
" \n",
" 23 | \n",
" MN | \n",
" 982.0 | \n",
"
\n",
" \n",
" 24 | \n",
" MS | \n",
" 607.0 | \n",
"
\n",
" \n",
" 25 | \n",
" MO | \n",
" 661.0 | \n",
"
\n",
" \n",
" 26 | \n",
" MT | \n",
" 0.0 | \n",
"
\n",
" \n",
" 27 | \n",
" NE | \n",
" 141.0 | \n",
"
\n",
" \n",
" 28 | \n",
" NV | \n",
" 361.0 | \n",
"
\n",
" \n",
" 29 | \n",
" NH | \n",
" 239.0 | \n",
"
\n",
" \n",
" 30 | \n",
" NJ | \n",
" 11981.0 | \n",
"
\n",
" \n",
" 31 | \n",
" NM | \n",
" 262.0 | \n",
"
\n",
" \n",
" 32 | \n",
" NY | \n",
" 28289.0 | \n",
"
\n",
" \n",
" 33 | \n",
" NC | \n",
" 490.0 | \n",
"
\n",
" \n",
" 34 | \n",
" ND | \n",
" 10.0 | \n",
"
\n",
" \n",
" 35 | \n",
" OH | \n",
" 1597.0 | \n",
"
\n",
" \n",
" 36 | \n",
" OK | \n",
" 277.0 | \n",
"
\n",
" \n",
" 37 | \n",
" OR | \n",
" 157.0 | \n",
"
\n",
" \n",
" 38 | \n",
" PA | \n",
" 5732.0 | \n",
"
\n",
" \n",
" 39 | \n",
" PR | \n",
" 0.0 | \n",
"
\n",
" \n",
" 40 | \n",
" RI | \n",
" 536.0 | \n",
"
\n",
" \n",
" 41 | \n",
" SC | \n",
" 484.0 | \n",
"
\n",
" \n",
" 42 | \n",
" SD | \n",
" 15.0 | \n",
"
\n",
" \n",
" 43 | \n",
" TN | \n",
" 306.0 | \n",
"
\n",
" \n",
" 44 | \n",
" TX | \n",
" 1619.0 | \n",
"
\n",
" \n",
" 45 | \n",
" UT | \n",
" 87.0 | \n",
"
\n",
" \n",
" 46 | \n",
" VT | \n",
" 16.0 | \n",
"
\n",
" \n",
" 47 | \n",
" VA | \n",
" 1406.0 | \n",
"
\n",
" \n",
" 48 | \n",
" WA | \n",
" 925.0 | \n",
"
\n",
" \n",
" 49 | \n",
" WV | \n",
" 57.0 | \n",
"
\n",
" \n",
" 50 | \n",
" WI | \n",
" 536.0 | \n",
"
\n",
" \n",
" 51 | \n",
" WY | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" State Deaths\n",
"0 AL 638.0\n",
"1 AK 0.0\n",
"2 AZ 799.0\n",
"3 AR 82.0\n",
"4 CA 3793.0\n",
"5 CO 1310.0\n",
"6 CT 2155.0\n",
"7 DE 346.0\n",
"8 DC 373.0\n",
"9 FL 2297.0\n",
"10 GA 1608.0\n",
"11 HI 0.0\n",
"12 ID 65.0\n",
"13 IL 4682.0\n",
"14 IN 1851.0\n",
"15 IA 464.0\n",
"16 KS 182.0\n",
"17 KY 366.0\n",
"18 LA 2191.0\n",
"19 ME 79.0\n",
"20 MD 2565.0\n",
"21 MA 6490.0\n",
"22 MI 4616.0\n",
"23 MN 982.0\n",
"24 MS 607.0\n",
"25 MO 661.0\n",
"26 MT 0.0\n",
"27 NE 141.0\n",
"28 NV 361.0\n",
"29 NH 239.0\n",
"30 NJ 11981.0\n",
"31 NM 262.0\n",
"32 NY 28289.0\n",
"33 NC 490.0\n",
"34 ND 10.0\n",
"35 OH 1597.0\n",
"36 OK 277.0\n",
"37 OR 157.0\n",
"38 PA 5732.0\n",
"39 PR 0.0\n",
"40 RI 536.0\n",
"41 SC 484.0\n",
"42 SD 15.0\n",
"43 TN 306.0\n",
"44 TX 1619.0\n",
"45 UT 87.0\n",
"46 VT 16.0\n",
"47 VA 1406.0\n",
"48 WA 925.0\n",
"49 WV 57.0\n",
"50 WI 536.0\n",
"51 WY 0.0"
]
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df1 = df.drop(columns=['Data as of', 'Start week', 'End Week', 'Sex', 'Total Deaths', 'Pneumonia Deaths', \n",
" 'Pneumonia and COVID-19 Deaths', 'Influenza Deaths', 'Pneumonia, Influenza, or COVID-19 Deaths', 'Footnote'])\n",
"df1 = df1.rename(columns={\"COVID-19 Deaths\":\"Deaths\", \"Age group\":\"Age\"})\n",
"df1[\"Age\"].replace({\"Under 1 year\": \"0-1 years\"}, inplace=True)\n",
"df1[\"State\"].replace({\"New York City\" : \"New York\"}, inplace=True)\n",
"df1 = df1[(df1.State != 'United States') & (df1.Age != 'All ages') & (df1.Age != 'All Ages')]\n",
"df1 = df1.groupby(['State'], as_index = False).sum()\n",
"df1['State'] = df1['State'].replace({\n",
" 'Alabama': 'AL',\n",
" 'Alaska': 'AK',\n",
" 'American Samoa': 'AS',\n",
" 'Arizona': 'AZ',\n",
" 'Arkansas': 'AR',\n",
" 'California': 'CA',\n",
" 'Colorado': 'CO',\n",
" 'Connecticut': 'CT',\n",
" 'Delaware': 'DE',\n",
" 'District of Columbia': 'DC',\n",
" 'Florida': 'FL',\n",
" 'Georgia': 'GA',\n",
" 'Guam': 'GU',\n",
" 'Hawaii': 'HI',\n",
" 'Idaho': 'ID',\n",
" 'Illinois': 'IL',\n",
" 'Indiana': 'IN',\n",
" 'Iowa': 'IA',\n",
" 'Kansas': 'KS',\n",
" 'Kentucky': 'KY',\n",
" 'Louisiana': 'LA',\n",
" 'Maine': 'ME',\n",
" 'Maryland': 'MD',\n",
" 'Massachusetts': 'MA',\n",
" 'Michigan': 'MI',\n",
" 'Minnesota': 'MN',\n",
" 'Mississippi': 'MS',\n",
" 'Missouri': 'MO',\n",
" 'Montana': 'MT',\n",
" 'Nebraska': 'NE',\n",
" 'Nevada': 'NV',\n",
" 'New Hampshire': 'NH',\n",
" 'New Jersey': 'NJ',\n",
" 'New Mexico': 'NM',\n",
" 'New York': 'NY',\n",
" 'North Carolina': 'NC',\n",
" 'North Dakota': 'ND',\n",
" 'Northern Mariana Islands':'MP',\n",
" 'Ohio': 'OH',\n",
" 'Oklahoma': 'OK',\n",
" 'Oregon': 'OR',\n",
" 'Pennsylvania': 'PA',\n",
" 'Puerto Rico': 'PR',\n",
" 'Rhode Island': 'RI',\n",
" 'South Carolina': 'SC',\n",
" 'South Dakota': 'SD',\n",
" 'Tennessee': 'TN',\n",
" 'Texas': 'TX',\n",
" 'Utah': 'UT',\n",
" 'Vermont': 'VT',\n",
" 'Virgin Islands': 'VI',\n",
" 'Virginia': 'VA',\n",
" 'Washington': 'WA',\n",
" 'West Virginia': 'WV',\n",
" 'Wisconsin': 'WI',\n",
" 'Wyoming': 'WY'\n",
"})\n",
"df1"
]
},
{
"cell_type": "code",
"execution_count": 147,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" State | \n",
" Deaths | \n",
" Latitude | \n",
" Longitude | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Alabama | \n",
" 638.0 | \n",
" 32.318231 | \n",
" -86.902298 | \n",
"
\n",
" \n",
" 1 | \n",
" Alaska | \n",
" 0.0 | \n",
" 63.588753 | \n",
" -154.493062 | \n",
"
\n",
" \n",
" 2 | \n",
" Arizona | \n",
" 799.0 | \n",
" 34.048928 | \n",
" -111.093731 | \n",
"
\n",
" \n",
" 3 | \n",
" Arkansas | \n",
" 82.0 | \n",
" 35.201050 | \n",
" -91.831833 | \n",
"
\n",
" \n",
" 4 | \n",
" California | \n",
" 3793.0 | \n",
" 36.778261 | \n",
" -119.417932 | \n",
"
\n",
" \n",
" 5 | \n",
" Colorado | \n",
" 1310.0 | \n",
" 39.550051 | \n",
" -105.782067 | \n",
"
\n",
" \n",
" 6 | \n",
" Connecticut | \n",
" 2155.0 | \n",
" 41.603221 | \n",
" -73.087749 | \n",
"
\n",
" \n",
" 7 | \n",
" Delaware | \n",
" 346.0 | \n",
" 38.910832 | \n",
" -75.527670 | \n",
"
\n",
" \n",
" 8 | \n",
" District of Columbia | \n",
" 373.0 | \n",
" 38.905985 | \n",
" -77.033418 | \n",
"
\n",
" \n",
" 9 | \n",
" Florida | \n",
" 2297.0 | \n",
" 27.664827 | \n",
" -81.515754 | \n",
"
\n",
" \n",
" 10 | \n",
" Georgia | \n",
" 1608.0 | \n",
" 32.157435 | \n",
" -82.907123 | \n",
"
\n",
" \n",
" 11 | \n",
" Hawaii | \n",
" 0.0 | \n",
" 19.898682 | \n",
" -155.665857 | \n",
"
\n",
" \n",
" 12 | \n",
" Idaho | \n",
" 65.0 | \n",
" 44.068202 | \n",
" -114.742041 | \n",
"
\n",
" \n",
" 13 | \n",
" Illinois | \n",
" 4682.0 | \n",
" 40.633125 | \n",
" -89.398528 | \n",
"
\n",
" \n",
" 14 | \n",
" Indiana | \n",
" 1851.0 | \n",
" 40.551217 | \n",
" -85.602364 | \n",
"
\n",
" \n",
" 15 | \n",
" Iowa | \n",
" 464.0 | \n",
" 41.878003 | \n",
" -93.097702 | \n",
"
\n",
" \n",
" 16 | \n",
" Kansas | \n",
" 182.0 | \n",
" 39.011902 | \n",
" -98.484246 | \n",
"
\n",
" \n",
" 17 | \n",
" Kentucky | \n",
" 366.0 | \n",
" 37.839333 | \n",
" -84.270018 | \n",
"
\n",
" \n",
" 18 | \n",
" Louisiana | \n",
" 2191.0 | \n",
" 31.244823 | \n",
" -92.145024 | \n",
"
\n",
" \n",
" 19 | \n",
" Maine | \n",
" 79.0 | \n",
" 45.253783 | \n",
" -69.445469 | \n",
"
\n",
" \n",
" 20 | \n",
" Maryland | \n",
" 2565.0 | \n",
" 39.045755 | \n",
" -76.641271 | \n",
"
\n",
" \n",
" 21 | \n",
" Massachusetts | \n",
" 6490.0 | \n",
" 42.407211 | \n",
" -71.382437 | \n",
"
\n",
" \n",
" 22 | \n",
" Michigan | \n",
" 4616.0 | \n",
" 44.314844 | \n",
" -85.602364 | \n",
"
\n",
" \n",
" 23 | \n",
" Minnesota | \n",
" 982.0 | \n",
" 46.729553 | \n",
" -94.685900 | \n",
"
\n",
" \n",
" 24 | \n",
" Mississippi | \n",
" 607.0 | \n",
" 32.354668 | \n",
" -89.398528 | \n",
"
\n",
" \n",
" 25 | \n",
" Missouri | \n",
" 661.0 | \n",
" 37.964253 | \n",
" -91.831833 | \n",
"
\n",
" \n",
" 26 | \n",
" Montana | \n",
" 0.0 | \n",
" 46.879682 | \n",
" -110.362566 | \n",
"
\n",
" \n",
" 27 | \n",
" Nebraska | \n",
" 141.0 | \n",
" 41.492537 | \n",
" -99.901813 | \n",
"
\n",
" \n",
" 28 | \n",
" Nevada | \n",
" 361.0 | \n",
" 38.802610 | \n",
" -116.419389 | \n",
"
\n",
" \n",
" 29 | \n",
" New Hampshire | \n",
" 239.0 | \n",
" 43.193852 | \n",
" -71.572395 | \n",
"
\n",
" \n",
" 30 | \n",
" New Jersey | \n",
" 11981.0 | \n",
" 40.058324 | \n",
" -74.405661 | \n",
"
\n",
" \n",
" 31 | \n",
" New Mexico | \n",
" 262.0 | \n",
" 34.972730 | \n",
" -105.032363 | \n",
"
\n",
" \n",
" 32 | \n",
" New York | \n",
" 28289.0 | \n",
" 43.299428 | \n",
" -74.217933 | \n",
"
\n",
" \n",
" 33 | \n",
" North Carolina | \n",
" 490.0 | \n",
" 35.759573 | \n",
" -79.019300 | \n",
"
\n",
" \n",
" 34 | \n",
" North Dakota | \n",
" 10.0 | \n",
" 47.551493 | \n",
" -101.002012 | \n",
"
\n",
" \n",
" 35 | \n",
" Ohio | \n",
" 1597.0 | \n",
" 40.417287 | \n",
" -82.907123 | \n",
"
\n",
" \n",
" 36 | \n",
" Oklahoma | \n",
" 277.0 | \n",
" 35.007752 | \n",
" -97.092877 | \n",
"
\n",
" \n",
" 37 | \n",
" Oregon | \n",
" 157.0 | \n",
" 43.804133 | \n",
" -120.554201 | \n",
"
\n",
" \n",
" 38 | \n",
" Pennsylvania | \n",
" 5732.0 | \n",
" 41.203322 | \n",
" -77.194525 | \n",
"
\n",
" \n",
" 39 | \n",
" Puerto Rico | \n",
" 0.0 | \n",
" 18.220833 | \n",
" -66.590149 | \n",
"
\n",
" \n",
" 40 | \n",
" Rhode Island | \n",
" 536.0 | \n",
" 41.580095 | \n",
" -71.477429 | \n",
"
\n",
" \n",
" 41 | \n",
" South Carolina | \n",
" 484.0 | \n",
" 33.836081 | \n",
" -81.163725 | \n",
"
\n",
" \n",
" 42 | \n",
" South Dakota | \n",
" 15.0 | \n",
" 43.969515 | \n",
" -99.901813 | \n",
"
\n",
" \n",
" 43 | \n",
" Tennessee | \n",
" 306.0 | \n",
" 35.517491 | \n",
" -86.580447 | \n",
"
\n",
" \n",
" 44 | \n",
" Texas | \n",
" 1619.0 | \n",
" 31.968599 | \n",
" -99.901813 | \n",
"
\n",
" \n",
" 45 | \n",
" Utah | \n",
" 87.0 | \n",
" 39.320980 | \n",
" -111.093731 | \n",
"
\n",
" \n",
" 46 | \n",
" Vermont | \n",
" 16.0 | \n",
" 44.558803 | \n",
" -72.577841 | \n",
"
\n",
" \n",
" 47 | \n",
" Virginia | \n",
" 1406.0 | \n",
" 37.431573 | \n",
" -78.656894 | \n",
"
\n",
" \n",
" 48 | \n",
" Washington | \n",
" 925.0 | \n",
" 47.751074 | \n",
" -120.740139 | \n",
"
\n",
" \n",
" 49 | \n",
" West Virginia | \n",
" 57.0 | \n",
" 38.597626 | \n",
" -80.454903 | \n",
"
\n",
" \n",
" 50 | \n",
" Wisconsin | \n",
" 536.0 | \n",
" 43.784440 | \n",
" -88.787868 | \n",
"
\n",
" \n",
" 51 | \n",
" Wyoming | \n",
" 0.0 | \n",
" 43.075968 | \n",
" -107.290284 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" State Deaths Latitude Longitude\n",
"0 Alabama 638.0 32.318231 -86.902298\n",
"1 Alaska 0.0 63.588753 -154.493062\n",
"2 Arizona 799.0 34.048928 -111.093731\n",
"3 Arkansas 82.0 35.201050 -91.831833\n",
"4 California 3793.0 36.778261 -119.417932\n",
"5 Colorado 1310.0 39.550051 -105.782067\n",
"6 Connecticut 2155.0 41.603221 -73.087749\n",
"7 Delaware 346.0 38.910832 -75.527670\n",
"8 District of Columbia 373.0 38.905985 -77.033418\n",
"9 Florida 2297.0 27.664827 -81.515754\n",
"10 Georgia 1608.0 32.157435 -82.907123\n",
"11 Hawaii 0.0 19.898682 -155.665857\n",
"12 Idaho 65.0 44.068202 -114.742041\n",
"13 Illinois 4682.0 40.633125 -89.398528\n",
"14 Indiana 1851.0 40.551217 -85.602364\n",
"15 Iowa 464.0 41.878003 -93.097702\n",
"16 Kansas 182.0 39.011902 -98.484246\n",
"17 Kentucky 366.0 37.839333 -84.270018\n",
"18 Louisiana 2191.0 31.244823 -92.145024\n",
"19 Maine 79.0 45.253783 -69.445469\n",
"20 Maryland 2565.0 39.045755 -76.641271\n",
"21 Massachusetts 6490.0 42.407211 -71.382437\n",
"22 Michigan 4616.0 44.314844 -85.602364\n",
"23 Minnesota 982.0 46.729553 -94.685900\n",
"24 Mississippi 607.0 32.354668 -89.398528\n",
"25 Missouri 661.0 37.964253 -91.831833\n",
"26 Montana 0.0 46.879682 -110.362566\n",
"27 Nebraska 141.0 41.492537 -99.901813\n",
"28 Nevada 361.0 38.802610 -116.419389\n",
"29 New Hampshire 239.0 43.193852 -71.572395\n",
"30 New Jersey 11981.0 40.058324 -74.405661\n",
"31 New Mexico 262.0 34.972730 -105.032363\n",
"32 New York 28289.0 43.299428 -74.217933\n",
"33 North Carolina 490.0 35.759573 -79.019300\n",
"34 North Dakota 10.0 47.551493 -101.002012\n",
"35 Ohio 1597.0 40.417287 -82.907123\n",
"36 Oklahoma 277.0 35.007752 -97.092877\n",
"37 Oregon 157.0 43.804133 -120.554201\n",
"38 Pennsylvania 5732.0 41.203322 -77.194525\n",
"39 Puerto Rico 0.0 18.220833 -66.590149\n",
"40 Rhode Island 536.0 41.580095 -71.477429\n",
"41 South Carolina 484.0 33.836081 -81.163725\n",
"42 South Dakota 15.0 43.969515 -99.901813\n",
"43 Tennessee 306.0 35.517491 -86.580447\n",
"44 Texas 1619.0 31.968599 -99.901813\n",
"45 Utah 87.0 39.320980 -111.093731\n",
"46 Vermont 16.0 44.558803 -72.577841\n",
"47 Virginia 1406.0 37.431573 -78.656894\n",
"48 Washington 925.0 47.751074 -120.740139\n",
"49 West Virginia 57.0 38.597626 -80.454903\n",
"50 Wisconsin 536.0 43.784440 -88.787868\n",
"51 Wyoming 0.0 43.075968 -107.290284"
]
},
"execution_count": 147,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2 = df.drop(columns=['Data as of', 'Start week', 'End Week', 'Sex', 'Total Deaths', 'Pneumonia Deaths', \n",
" 'Pneumonia and COVID-19 Deaths', 'Influenza Deaths', 'Pneumonia, Influenza, or COVID-19 Deaths', 'Footnote'])\n",
"df2 = df2.rename(columns={\"COVID-19 Deaths\":\"Deaths\", \"Age group\":\"Age\"})\n",
"df2[\"Age\"].replace({\"Under 1 year\": \"0-1 years\"}, inplace=True)\n",
"df2[\"State\"].replace({\"New York City\" : \"New York\"}, inplace=True)\n",
"df2 = df2[(df2.State != 'United States') & (df2.Age != 'All ages') & (df2.Age != 'All Ages')]\n",
"df2 = df2.groupby(['State'], as_index = False).sum()\n",
"df3 = pd.read_html('https://developers.google.com/public-data/docs/canonical/states_csv')[0]\n",
"df3 = df3.rename(columns={\"latitude\": \"Latitude\", \"longitude\": \"Longitude\", \"name\":\"State\" })\n",
"df3 = df3.drop(columns='state')\n",
"df3 = df3[['State', 'Latitude', 'Longitude']]\n",
"df5 = pd.merge(df2, df3, on=('State'))\n",
"df5"
]
},
{
"cell_type": "code",
"execution_count": 148,
"metadata": {},
"outputs": [],
"source": [
"url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'\n",
"state_geo = f'{url}/us-states.json'"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Make this Notebook Trusted to load map: File -> Trust Notebook
"
],
"text/plain": [
""
]
},
"execution_count": 149,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Covid_19 = folium.Map(location=[37.0902, -95.7129], tiles='Stamen Toner', zoom_start=3,)\n",
"Covid_19.choropleth(geo_data=state_geo,\n",
" data=df1,\n",
" columns=['State', 'Deaths'],\n",
" key_on='feature.id',\n",
" fill_color='YlOrRd', \n",
" fill_opacity=0.7, \n",
" line_opacity=0.2,\n",
" legend_name='CDC COVID 19 Deaths'\n",
")\n",
"\n",
"folium.LayerControl().add_to(Covid_19)\n",
"\n",
"for lat, lng, State, Deaths in zip(df5['Latitude'], df5['Longitude'], df5['State'], df5['Deaths']):\n",
" label = 'State: {} Deaths: {}'.format(State,Deaths)\n",
" label = folium.Popup(label, parse_html=True)\n",
" folium.CircleMarker(\n",
" [lat, lng],\n",
" radius=5,\n",
" popup=label,\n",
" color='red',\n",
" fill=True,\n",
" fill_opacity=0.7,\n",
" parse_html=False).add_to(Covid_19) \n",
"\n",
"Covid_19"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Feedback:CDC data is limited and suppressed, if you check the data itself \"..suppressed in accordance with NCHS confidentiality standards.\" there is a clear indication that the data itself is very limited. The data was published May 7 as well during this notebook publishing.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"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.6.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}