{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
StateDeaths
0AL638.0
1AK0.0
2AZ799.0
3AR82.0
4CA3793.0
5CO1310.0
6CT2155.0
7DE346.0
8DC373.0
9FL2297.0
10GA1608.0
11HI0.0
12ID65.0
13IL4682.0
14IN1851.0
15IA464.0
16KS182.0
17KY366.0
18LA2191.0
19ME79.0
20MD2565.0
21MA6490.0
22MI4616.0
23MN982.0
24MS607.0
25MO661.0
26MT0.0
27NE141.0
28NV361.0
29NH239.0
30NJ11981.0
31NM262.0
32NY28289.0
33NC490.0
34ND10.0
35OH1597.0
36OK277.0
37OR157.0
38PA5732.0
39PR0.0
40RI536.0
41SC484.0
42SD15.0
43TN306.0
44TX1619.0
45UT87.0
46VT16.0
47VA1406.0
48WA925.0
49WV57.0
50WI536.0
51WY0.0
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
StateDeathsLatitudeLongitude
0Alabama638.032.318231-86.902298
1Alaska0.063.588753-154.493062
2Arizona799.034.048928-111.093731
3Arkansas82.035.201050-91.831833
4California3793.036.778261-119.417932
5Colorado1310.039.550051-105.782067
6Connecticut2155.041.603221-73.087749
7Delaware346.038.910832-75.527670
8District of Columbia373.038.905985-77.033418
9Florida2297.027.664827-81.515754
10Georgia1608.032.157435-82.907123
11Hawaii0.019.898682-155.665857
12Idaho65.044.068202-114.742041
13Illinois4682.040.633125-89.398528
14Indiana1851.040.551217-85.602364
15Iowa464.041.878003-93.097702
16Kansas182.039.011902-98.484246
17Kentucky366.037.839333-84.270018
18Louisiana2191.031.244823-92.145024
19Maine79.045.253783-69.445469
20Maryland2565.039.045755-76.641271
21Massachusetts6490.042.407211-71.382437
22Michigan4616.044.314844-85.602364
23Minnesota982.046.729553-94.685900
24Mississippi607.032.354668-89.398528
25Missouri661.037.964253-91.831833
26Montana0.046.879682-110.362566
27Nebraska141.041.492537-99.901813
28Nevada361.038.802610-116.419389
29New Hampshire239.043.193852-71.572395
30New Jersey11981.040.058324-74.405661
31New Mexico262.034.972730-105.032363
32New York28289.043.299428-74.217933
33North Carolina490.035.759573-79.019300
34North Dakota10.047.551493-101.002012
35Ohio1597.040.417287-82.907123
36Oklahoma277.035.007752-97.092877
37Oregon157.043.804133-120.554201
38Pennsylvania5732.041.203322-77.194525
39Puerto Rico0.018.220833-66.590149
40Rhode Island536.041.580095-71.477429
41South Carolina484.033.836081-81.163725
42South Dakota15.043.969515-99.901813
43Tennessee306.035.517491-86.580447
44Texas1619.031.968599-99.901813
45Utah87.039.320980-111.093731
46Vermont16.044.558803-72.577841
47Virginia1406.037.431573-78.656894
48Washington925.047.751074-120.740139
49West Virginia57.038.597626-80.454903
50Wisconsin536.043.784440-88.787868
51Wyoming0.043.075968-107.290284
\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 }