USA County Health Rankings

Create CSV files for choropleth maps of the USA displaying data from County Health Rankings.

In [1]:
import pandas as pd

# FIPS as string so leading zeros are kept
converters = {'FIPS': str}

df = pd.read_excel('data/2014 County Health Rankings Data - v1.xls', 'Ranked Measure Data', skiprows=1, converters=converters)
df.head()
Out[1]:
FIPS State County Deaths YPLL Rate 95% CI - Low 95% CI - High Quartile Sample Size % Fair/Poor ... # Households with Severe Problems % Severe Housing Problems Quartile.31 # Drive Alone Workers % Drive Alone Quartile.32 Workers who Drive Alone Long Commute - Drives Alone Quartile.33
0 01001 Alabama Autauga 729 8376.42 7522.076 9230.764 1 407 22.8 ... 2300 11.663286 1 21393 24369 87.787763 4 21393 41.9 3
1 01003 Alabama Baldwin 2325 7770.16 7291.646 8248.674 1 1664 12.7 ... 9370 13.486866 2 66189 79588 83.164547 2 66189 35.2 3
2 01005 Alabama Barbour 422 9458.14 8107.935 10808.345 2 423 23.4 ... 1650 16.845329 4 7431 8990 82.658509 2 7431 31.5 2
3 01007 Alabama Bibb 390 11543.90 9945.206 13142.594 4 379 17.9 ... 710 9.543011 1 6888 8366 82.333254 2 6888 49.7 4
4 01009 Alabama Blount 826 8505.64 7672.032 9339.248 1 367 24.2 ... 2595 12.594031 2 18606 23117 80.486222 1 18606 60.3 4

5 rows × 147 columns

USA Alcohol-Impaired Driving Deaths

  • # Alcohol-Impaired Driving Deaths: The total number of alcohol-impaired motor vehicle deaths
  • # Driving Deaths: The total number of motor vehicle deaths
  • % Alcohol-Impaired: Percent of driving deaths with alcohol involvement

Select relevant columns and drop NA values so columns can be converted to integers, see Support for integer NA.

In [2]:
df_out = df.copy()[['FIPS', '# Alcohol-Impaired Driving Deaths', '# Driving Deaths', '% Alcohol-Impaired']]
df_out.dropna(inplace=True)
df_out['# Alcohol-Impaired Driving Deaths'] = df_out['# Alcohol-Impaired Driving Deaths'].astype(int, copy=False)
df_out['# Driving Deaths'] = df_out['# Driving Deaths'].astype(int, copy=False)

Adapt column names to map title and write CSV file.

In [3]:
df_out.columns = ['FIPS', 'Total Number with Alcohol Involvement', 'Total Number', 'Percent with Alcohol Involvement']
df_out.to_csv('../static/data/csv/usa-alcohol-driving-deaths.csv', encoding='utf-8', index=False)

Physically Inactive

Percent of adults that report no leisure time physical activity.

In [4]:
df_out = df.copy()[['FIPS', '% Physically Inactive']]
df_out.dropna(inplace=True)
In [5]:
df_out.columns = ['FIPS', '% Physically Inactive']
df_out.to_csv('../static/data/csv/usa-physically-inactive.csv', encoding='utf-8', index=False)

Map Preview


Ramiro Gómez

About this post

This post was written by Ramiro Gómez (@yaph) and published on November 14, 2014.


blog comments powered by Disqus