In this notebook we are doing a simple visualization creating Choropleth Maps at county level. For this example we are using data released by Johns Hopkins University (https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_daily_reports) for March 30, 2020 and the US county dataset (https://www.arcgis.com/home/item.html?id=a00d6b6149b34ed3b833e10fb72ef47b). This notebook creates choropleth maps of confirmed cases, deaths, cases per-capita and deaths per-capita for all of USA, continental US, and Illinois.
# import required libraries
import os
import fiona
# pretty printing - makes some kinds of text output easier to read
import pprint
import IPython
from matplotlib import pyplot as plt
import pandas as pd
import geopandas as gpd
from shapely.geometry import Polygon
%matplotlib inline
!wget https://ndownloader.figshare.com/files/22156113?private_link=2f0d5e4d3807a40c5702 -O USA_Counties_as_Shape.zip
!wget https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/03-30-2020.csv -O 03-30-2020.csv
# import county database
county_gpd = gpd.read_file('zip://./USA_Counties_as_Shape.zip')
#Import one day of data from the Johns Hopkins University
oneday_df = pd.read_csv('./03-30-2020.csv')
#Keep only US Data
select_us= oneday_df.dropna()
county_gpd['STATE_FIPS']=county_gpd['STATE_FIPS'].astype(int)
# Drop data of US territories
county_gpd = county_gpd.loc[county_gpd['STATE_FIPS'] <= 56]
select_us.head()
select_us['FIPS']=select_us['FIPS'].astype(int)
county_gpd['FIPS']=county_gpd['FIPS'].astype(int)
county_gpd.head()
select_us.head()
county_covid = county_gpd.merge(
select_us, on='FIPS')
county_covid.head()
#Change data types so you can do comparisons
county_covid['Lat']=county_covid['Lat'].astype(float)
county_covid['Long_']=county_covid['Long_'].astype(float)
county_covid_cont=county_covid
# Continental USBound: -126.562500,24.046464,-65.390625,49.610710
county_covid_cont = county_covid_cont.loc[county_covid_cont['Lat'] <= 49.610710]
county_covid_cont = county_covid_cont.loc[county_covid_cont['Lat'] >= 24.046464]
county_covid_cont = county_covid_cont.loc[county_covid_cont['Long_'] <= -65.390625]
county_covid_cont = county_covid_cont.loc[county_covid_cont['Long_'] >= -126.562500]
county_covid_cont.plot(figsize=(15, 15), column='Confirmed', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'lower left', 'title':'Number of Confirmed Cases'})
plt.title("Number of Confirmed Cases")
county_covid.plot(figsize=(15, 15), column='Confirmed', cmap='OrRd', scheme='fisher_jenks',
legend="true",legend_kwds={'loc': 'best', 'title':'Number of Confirmed Cases'})
plt.title("Number of Confirmed Cases")
#-91.513079 36.970298 -87.494756 42.508481
county_covid_il = county_covid.loc[county_covid['STATE_FIPS'] == 17]
county_covid_il.plot(figsize=(10, 10), column='Confirmed', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'lower left','title':'Number of Confirmed Cases'})
plt.title("Number of Confirmed Cases")
county_covid_cont.plot(figsize=(20, 10), column='Deaths', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'lower left','title':'Number of Deaths'})
plt.title("Number of Deaths")
county_covid.plot(figsize=(30, 30), column='Deaths', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'best','title':'Number of Deaths'})
plt.title("Number of Deaths")
county_covid_il.plot(figsize=(20, 15), column='Deaths', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'lower left','title':'Number of Deaths'} )
plt.title("Number of Deaths")
county_covid_cont['Confirmed_per_capita']=county_covid_cont['Confirmed']*1000000/county_covid_cont['POP2012']
county_covid_cont.plot(figsize=(20, 10), column='Confirmed_per_capita', cmap='OrRd', scheme='fisher_jenks',
legend="true",
legend_kwds={'loc': 'lower left','title':'Number of confirmed cases per Million population'})
plt.title("Confirmed cases per Million population")
county_covid['Confirmed_per_capita']=county_covid['Confirmed']*1000000/county_covid['POP2012']
county_covid.plot(figsize=(15, 10), column='Confirmed_per_capita', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'best','title':'Number of confirmed cases per Million population'})
plt.title("Confirmed cases per Million population")
county_covid_il['Confirmed_per_capita']=county_covid_il['Confirmed']*1000000/county_covid_il['POP2012']
county_covid_il.plot(figsize=(20, 10), column='Confirmed_per_capita', cmap='OrRd', scheme='fisher_jenks',
legend="true",
legend_kwds={'loc': 'lower left','title':'Number of confirmed cases per Million population'})
plt.title("Confirmed cases per Million population")
county_covid_cont['Deaths_per_capita']=county_covid_cont['Deaths']*1000000/county_covid_cont['POP2012']
county_covid_cont.plot(figsize=(20, 10), column='Deaths_per_capita', cmap='OrRd', scheme='fisher_jenks',
legend="true",
legend_kwds={'loc': 'lower left','title':'Number of Deaths per Million population'})
plt.title("Deaths per Million population")
county_covid['Deaths_per_capita']=county_covid['Deaths']*1000000/county_covid['POP2012']
county_covid.plot(figsize=(30, 30), column='Deaths_per_capita', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'best','title':'Number of Deaths per Million population'})
plt.title("Deaths per Million population")
county_covid_il['Deaths_per_capita']=county_covid_il['Deaths']*1000000/county_covid_il['POP2012']
county_covid_il.plot(figsize=(20, 10), column='Deaths_per_capita', cmap='OrRd', scheme='fisher_jenks', legend="true",
legend_kwds={'loc': 'lower left','title':'Number of Deaths per Million population'})
plt.title("Deaths per Million population")