Visualizing COVID-19 Vulnerability With Plot.ly For Python

A quick walk-through on creating choropleth using the Plot.ly module for Python.

Image for post
(Image by author)

Introduction

Data

Notebook

Data Reading and Cleaning

import pandas as pd
import numpy as np
import plotly.express as pxdf = pd.read_csv("data/CDC_SVI.csv")
df.head(10)
Image for post
(Image by author)

That’s a lot of columns!

df = pd.DataFrame({"FIPS": df["FIPS"], "POP": df["E_TOTPOP"], 
"HOUSEHOLDS": df["E_HH"], "POV": df["E_POV"], "UNEMP": df["E_UNEMP"],
"PCI": df["M_PCI"], "DIS": df["E_DISABL"], "UNINS": df["E_UNINSUR"]})
Image for post
(Image by author)

Feature Chloropleths

from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
current_feature = "POV"
curr_min = min(df[current_feature])
curr_max = max(df[current_feature])
fig = px.choropleth(df, geojson=counties, locations='FIPS', color=current_feature,
color_continuous_scale="reds",
range_color=(curr_min, curr_max),
scope="usa",
labels={current_feature: current_feature}
)
fig.update_layout(title_text = "US Poverty by county")
fig.show()
Image for post
(Image by author)
More:  Truck drivers in Manitoba share experiences from the first 6 months of the pandemic
current_feature = "POP"
curr_min = min(df[current_feature])
curr_max = max(df[current_feature])
fig = px.choropleth(df, geojson=counties, locations='FIPS', color=current_feature,
color_continuous_scale="blues",
range_color=(curr_min, curr_max),
scope="usa",
labels={current_feature: "Population"}
)
fig.update_layout(title_text = "US Population by county")
fig.show()
Image for post
(Image by author)
Image for post
(Image by author)
current_feature = "HOUSEHOLDS"
curr_min = min(df[current_feature])
curr_max = max(df[current_feature])
fig = px.choropleth(df, geojson=counties, locations='FIPS', color=current_feature,
color_continuous_scale="greens",
range_color=(curr_min, curr_max),
scope="usa",
labels={current_feature: "Population"}
)
fig.update_layout(title_text = "US Household Count By County")
fig.show()
Image for post
(Image by author)

Feature Engineering

POPPERH = lambda pop, hh: pop / hh
df["POPPERH"] = POPPERH(df["POP"], df["HOUSEHOLDS"])
Image for post
(Image by author)

RVRI

Image for post
# (unemp + POV + UNINS / POPPERH) + POV 
RVRI = lambda df: (df["UNEMP"] + df["POV"] + df["UNINS"] / df["POPPERH"]) + df["POP"]
df["RVRI"] = RVRI(df)
Image for post
(Image by author)

Conclusion


More from: | Category: Coronavirus News