Gauging the changes in the US economy from 1970 - 2013 by visualizing mean income on a county-scale over time

I wanted to see how mean income (normalized to 2015 USD values) changed over time. In particular, I had two main questions:

  1. Has the economic conditions for the average person changed since 1970?
  2. Is the income inequality of present times substantially different than what we've seen in the past?

By visualizing mean income versus population on a county-scale over time, I found that income has risen overall (even for the poorest counties) but the inequality is also slightly more severe than it has been (though this has been tempered by the 2008 economic crisis).

Much more analysis, and some nice visualizations using kernel density estimation (KDE) can be found in the README from my original github repository where I first posted this code.

Here's an example of the KDE visualization:

...and some plots that show how things have changed for the nation as a whole:

...and for the counties which make up the NYC metro area:

The following demonstration is taken from that repository as well, but with some minor modifications to make use of the supplied pickles and other data so that users will not have to download any external material or wait for the aggregation process (which takes several minutes).


In [1]:
import analysis
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.io import output_notebook, gridplot
from bokeh.palettes import brewer

In [2]:
# call this to set up bokeh integration
output_notebook()


BokehJS successfully loaded.

First, let's load the aggregate dataframes from the pickles and prepare the dictionary of county names and FIPS codes:


In [3]:
PCPI_data = pd.read_pickle('PCPI_agg.p')
POP_data  = pd.read_pickle('POP_agg.p')

counties  = analysis.get_county_dict('national_county.txt')

Let's take a quick look at what these objects look like:


In [4]:
counties
# Format of {FIPS Code : Name}


Out[4]:
{'16079': 'Shoshone County, ID',
 '33017': 'Strafford County, NH',
 '16073': 'Owyhee County, ID',
 '16071': 'Oneida County, ID',
 '16077': 'Power County, ID',
 '16075': 'Payette County, ID',
 '48093': 'Comanche County, TX',
 '06115': 'Yuba County, CA',
 '06111': 'Ventura County, CA',
 '06113': 'Yolo County, CA',
 '01129': 'Washington County, AL',
 '46111': 'Sanborn County, SD',
 '40145': 'Wagoner County, OK',
 '02100': 'Haines Borough, AK',
 '02105': 'Hoonah-Angoon Census Area, AK',
 '40147': 'Washington County, OK',
 '19159': 'Ringgold County, IA',
 '39109': 'Miami County, OH',
 '19155': 'Pottawattamie County, IA',
 '39105': 'Meigs County, OH',
 '19157': 'Poweshiek County, IA',
 '39107': 'Mercer County, OH',
 '19151': 'Pocahontas County, IA',
 '39101': 'Marion County, OH',
 '19153': 'Polk County, IA',
 '39103': 'Medina County, OH',
 '40029': 'Coal County, OK',
 '40143': 'Tulsa County, OK',
 '48025': 'Bee County, TX',
 '22009': 'Avoyelles Parish, LA',
 '40027': 'Cleveland County, OK',
 '22001': 'Acadia Parish, LA',
 '22003': 'Allen Parish, LA',
 '22005': 'Ascension Parish, LA',
 '13029': 'Bryan County, GA',
 '22007': 'Assumption Parish, LA',
 '06029': 'Kern County, CA',
 '46113': 'Shannon County, SD',
 '06021': 'Glenn County, CA',
 '40023': 'Choctaw County, OK',
 '06023': 'Humboldt County, CA',
 '06025': 'Imperial County, CA',
 '06027': 'Inyo County, CA',
 '27173': 'Yellow Medicine County, MN',
 '27171': 'Wright County, MN',
 '51600': 'Fairfax city, VA',
 '33013': 'Merrimack County, NH',
 '21101': 'Henderson County, KY',
 '21103': 'Henry County, KY',
 '21105': 'Hickman County, KY',
 '21107': 'Hopkins County, KY',
 '21109': 'Jackson County, KY',
 '32013': 'Humboldt County, NV',
 '32011': 'Eureka County, NV',
 '51840': 'Winchester city, VA',
 '32017': 'Lincoln County, NV',
 '32015': 'Lander County, NV',
 '47081': 'Hickman County, TN',
 '32019': 'Lyon County, NV',
 '26157': 'Tuscola County, MI',
 '41001': 'Baker County, OR',
 '26155': 'Shiawassee County, MI',
 '42057': 'Fulton County, PA',
 '12019': 'Clay County, FL',
 '42051': 'Fayette County, PA',
 '26151': 'Sanilac County, MI',
 '42053': 'Forest County, PA',
 '12015': 'Charlotte County, FL',
 '12017': 'Citrus County, FL',
 '12011': 'Broward County, FL',
 '42059': 'Greene County, PA',
 '12013': 'Calhoun County, FL',
 '51115': 'Mathews County, VA',
 '46009': 'Bon Homme County, SD',
 '55109': 'St. Croix County, WI',
 '51111': 'Lunenburg County, VA',
 '51113': 'Madison County, VA',
 '46003': 'Aurora County, SD',
 '46007': 'Bennett County, SD',
 '53007': 'Chelan County, WA',
 '46005': 'Beadle County, SD',
 '17031': 'Cook County, IL',
 '17033': 'Crawford County, IL',
 '48021': 'Bastrop County, TX',
 '17035': 'Cumberland County, IL',
 '05139': 'Union County, AR',
 '05137': 'Stone County, AR',
 '05135': 'Sharp County, AR',
 '05133': 'Sevier County, AR',
 '05131': 'Sebastian County, AR',
 '46117': 'Stanley County, SD',
 '54027': 'Hampshire County, WV',
 '26023': 'Branch County, MI',
 '05003': 'Ashley County, AR',
 '26021': 'Berrien County, MI',
 '05001': 'Arkansas County, AR',
 '26027': 'Cass County, MI',
 '05007': 'Benton County, AR',
 '26025': 'Calhoun County, MI',
 '05005': 'Baxter County, AR',
 '12121': 'Suwannee County, FL',
 '12123': 'Taylor County, FL',
 '05009': 'Boone County, AR',
 '12125': 'Union County, FL',
 '12127': 'Volusia County, FL',
 '48261': 'Kenedy County, TX',
 '20153': 'Rawlins County, KS',
 '01025': 'Clarke County, AL',
 '01027': 'Clay County, AL',
 '01021': 'Chilton County, AL',
 '01023': 'Choctaw County, AL',
 '01029': 'Cleburne County, AL',
 '37009': 'Ashe County, NC',
 '37007': 'Anson County, NC',
 '37005': 'Alleghany County, NC',
 '37003': 'Alexander County, NC',
 '37001': 'Alamance County, NC',
 '48365': 'Panola County, TX',
 '36029': 'Erie County, NY',
 '42129': 'Westmoreland County, PA',
 '48237': 'Jack County, TX',
 '36023': 'Cortland County, NY',
 '36021': 'Columbia County, NY',
 '36027': 'Dutchess County, NY',
 '36025': 'Delaware County, NY',
 '48091': 'Comal County, TX',
 '42125': 'Washington County, PA',
 '48235': 'Irion County, TX',
 '48233': 'Hutchinson County, TX',
 '51065': 'Fluvanna County, VA',
 '48149': 'Fayette County, TX',
 '48419': 'Shelby County, TX',
 '48145': 'Falls County, TX',
 '48147': 'Fannin County, TX',
 '48141': 'El Paso County, TX',
 '48143': 'Erath County, TX',
 '01111': 'Randolph County, AL',
 '01113': 'Russell County, AL',
 '01115': 'St. Clair County, AL',
 '01117': 'Shelby County, AL',
 '01119': 'Sumter County, AL',
 '45061': 'Lee County, SC',
 '13059': 'Clarke County, GA',
 '45065': 'McCormick County, SC',
 '45067': 'Marion County, SC',
 '13053': 'Chattahoochee County, GA',
 '13051': 'Chatham County, GA',
 '13057': 'Cherokee County, GA',
 '13055': 'Chattooga County, GA',
 '48231': 'Hunt County, TX',
 '01045': 'Dale County, AL',
 '40073': 'Kingfisher County, OK',
 '37177': 'Tyrrell County, NC',
 '37175': 'Transylvania County, NC',
 '37173': 'Swain County, NC',
 '37171': 'Surry County, NC',
 '37179': 'Union County, NC',
 '08053': 'Hinsdale County, CO',
 '08051': 'Gunnison County, CO',
 '48029': 'Bexar County, TX',
 '08057': 'Jackson County, CO',
 '08055': 'Huerfano County, CO',
 '08059': 'Jefferson County, CO',
 '54089': 'Summers County, WV',
 '31129': 'Nuckolls County, NE',
 '31127': 'Nemaha County, NE',
 '31125': 'Nance County, NE',
 '31123': 'Morrill County, NE',
 '31121': 'Merrick County, NE',
 '18149': 'Starke County, IN',
 '54085': 'Ritchie County, WV',
 '37125': 'Moore County, NC',
 '18141': 'St. Joseph County, IN',
 '18143': 'Scott County, IN',
 '18145': 'Shelby County, IN',
 '18147': 'Spencer County, IN',
 '37127': 'Nash County, NC',
 '37121': 'Mitchell County, NC',
 '29109': 'Lawrence County, MO',
 '46011': 'Brookings County, SD',
 '05093': 'Mississippi County, AR',
 '29101': 'Johnson County, MO',
 '29103': 'Knox County, MO',
 '37123': 'Montgomery County, NC',
 '29105': 'Laclede County, MO',
 '29107': 'Lafayette County, MO',
 '55111': 'Sauk County, WI',
 '55113': 'Sawyer County, WI',
 '55115': 'Shawano County, WI',
 '55117': 'Sheboygan County, WI',
 '48303': 'Lubbock County, TX',
 '55119': 'Taylor County, WI',
 '34041': 'Warren County, NJ',
 '46013': 'Brown County, SD',
 '48301': 'Loving County, TX',
 '48307': 'McCulloch County, TX',
 '51161': 'Roanoke County, VA',
 '54081': 'Raleigh County, WV',
 '48305': 'Lynn County, TX',
 '47035': 'Cumberland County, TN',
 '47037': 'Davidson County, TN',
 '47031': 'Coffee County, TN',
 '47033': 'Crockett County, TN',
 '06109': 'Tuolumne County, CA',
 '06107': 'Tulare County, CA',
 '06105': 'Trinity County, CA',
 '47039': 'Decatur County, TN',
 '06103': 'Tehama County, CA',
 '06101': 'Sutter County, CA',
 '46137': 'Ziebach County, SD',
 '55029': 'Door County, WI',
 '19149': 'Plymouth County, IA',
 '39171': 'Williams County, OH',
 '19147': 'Palo Alto County, IA',
 '39173': 'Wood County, OH',
 '19145': 'Page County, IA',
 '39175': 'Wyandot County, OH',
 '19143': 'Osceola County, IA',
 '55023': 'Crawford County, WI',
 '19141': "O'Brien County, IA",
 '54083': 'Randolph County, WV',
 '40141': 'Tillman County, OK',
 '30049': 'Lewis and Clark County, MT',
 '22019': 'Calcasieu Parish, LA',
 '22013': 'Bienville Parish, LA',
 '22011': 'Beauregard Parish, LA',
 '22017': 'Caddo Parish, LA',
 '22015': 'Bossier Parish, LA',
 '46129': 'Walworth County, SD',
 '06039': 'Madera County, CA',
 '06033': 'Lake County, CA',
 '06031': 'Kings County, CA',
 '06037': 'Los Angeles County, CA',
 '06035': 'Lassen County, CA',
 '27143': 'Sibley County, MN',
 '16065': 'Madison County, ID',
 '27141': 'Sherburne County, MN',
 '16067': 'Minidoka County, ID',
 '27147': 'Steele County, MN',
 '16061': 'Lewis County, ID',
 '27145': 'Stearns County, MN',
 '16063': 'Lincoln County, ID',
 '51510': 'Alexandria city, VA',
 '27149': 'Stevens County, MN',
 '51530': 'Buena Vista city, VA',
 '39009': 'Athens County, OH',
 '16069': 'Nez Perce County, ID',
 '21113': 'Jessamine County, KY',
 '21111': 'Jefferson County, KY',
 '21117': 'Kenton County, KY',
 '21115': 'Johnson County, KY',
 '48447': 'Throckmorton County, TX',
 '21119': 'Knott County, KY',
 '56045': 'Weston County, WY',
 '32009': 'Esmeralda County, NV',
 '32005': 'Douglas County, NV',
 '32007': 'Elko County, NV',
 '32001': 'Churchill County, NV',
 '32003': 'Clark County, NV',
 '42021': 'Cambria County, PA',
 '26141': 'Presque Isle County, MI',
 '42023': 'Cameron County, PA',
 '26143': 'Roscommon County, MI',
 '42025': 'Carbon County, PA',
 '26145': 'Saginaw County, MI',
 '42027': 'Centre County, PA',
 '12009': 'Brevard County, FL',
 '42029': 'Chester County, PA',
 '26149': 'St. Joseph County, MI',
 '12005': 'Bay County, FL',
 '12003': 'Baker County, FL',
 '12001': 'Alachua County, FL',
 '51107': 'Loudoun County, VA',
 '51105': 'Lee County, VA',
 '51103': 'Lancaster County, VA',
 '51101': 'King William County, VA',
 '51109': 'Louisa County, VA',
 '05109': 'Pike County, AR',
 '05103': 'Ouachita County, AR',
 '05101': 'Newton County, AR',
 '05107': 'Phillips County, AR',
 '05105': 'Perry County, AR',
 '13289': 'Twiggs County, GA',
 '13287': 'Turner County, GA',
 '51127': 'New Kent County, VA',
 '13285': 'Troup County, GA',
 '13283': 'Treutlen County, GA',
 '13281': 'Towns County, GA',
 '46099': 'Minnehaha County, SD',
 '48121': 'Denton County, TX',
 '30061': 'Mineral County, MT',
 '48219': 'Hockley County, TX',
 '48127': 'Dimmit County, TX',
 '53039': 'Klickitat County, WA',
 '30063': 'Missoula County, MT',
 '26039': 'Crawford County, MI',
 '05039': 'Dallas County, AR',
 '49047': 'Uintah County, UT',
 '05037': 'Cross County, AR',
 '12133': 'Washington County, FL',
 '05035': 'Crittenden County, AR',
 '26037': 'Clinton County, MI',
 '05033': 'Crawford County, AR',
 '26031': 'Cheboygan County, MI',
 '05031': 'Craighead County, AR',
 '26033': 'Chippewa County, MI',
 '49045': 'Tooele County, UT',
 '48229': 'Hudspeth County, TX',
 '20089': 'Jewell County, KS',
 '20087': 'Jefferson County, KS',
 '20085': 'Jackson County, KS',
 '30067': 'Park County, MT',
 '20083': 'Hodgeman County, KS',
 '20081': 'Haskell County, KS',
 '49043': 'Summit County, UT',
 '01051': 'Elmore County, AL',
 '01053': 'Escambia County, AL',
 '01055': 'Etowah County, AL',
 '01057': 'Fayette County, AL',
 '01059': 'Franklin County, AL',
 '49041': 'Sevier County, UT',
 '36017': 'Chenango County, NY',
 '37019': 'Brunswick County, NC',
 '13199': 'Meriwether County, GA',
 '36013': 'Chautauqua County, NY',
 '36011': 'Cayuga County, NY',
 '13193': 'Macon County, GA',
 '37011': 'Avery County, NC',
 '13191': 'McIntosh County, GA',
 '37013': 'Beaufort County, NC',
 '13197': 'Marion County, GA',
 '37015': 'Bertie County, NC',
 '13195': 'Madison County, GA',
 '37017': 'Bladen County, NC',
 '48311': 'McMullen County, TX',
 '48313': 'Madison County, TX',
 '48315': 'Marion County, TX',
 '48317': 'Martin County, TX',
 '48319': 'Mason County, TX',
 '48139': 'Ellis County, TX',
 '48429': 'Stephens County, TX',
 '48131': 'Duval County, TX',
 '48133': 'Eastland County, TX',
 '48135': 'Ector County, TX',
 '48137': 'Edwards County, TX',
 '47175': 'Van Buren County, TN',
 '13067': 'Cobb County, GA',
 '36075': 'Oswego County, NY',
 '13065': 'Clinch County, GA',
 '13063': 'Clayton County, GA',
 '55011': 'Buffalo County, WI',
 '13061': 'Clay County, GA',
 '47177': 'Warren County, TN',
 '47069': 'Hardeman County, TN',
 '13069': 'Coffee County, GA',
 '13265': 'Taliaferro County, GA',
 '13267': 'Tattnall County, GA',
 '13261': 'Sumter County, GA',
 '13263': 'Talbot County, GA',
 '13269': 'Taylor County, GA',
 '42055': 'Franklin County, PA',
 '45089': 'Williamsburg County, SC',
 '40089': 'McCurtain County, OK',
 '48047': 'Brooks County, TX',
 '48217': 'Hill County, TX',
 '48041': 'Brazos County, TX',
 '48043': 'Brewster County, TX',
 '40081': 'Lincoln County, OK',
 '26153': 'Schoolcraft County, MI',
 '40083': 'Logan County, OK',
 '40085': 'Love County, OK',
 '40087': 'McClain County, OK',
 '20065': 'Graham County, KS',
 '37161': 'Rutherford County, NC',
 '20067': 'Grant County, KS',
 '37163': 'Sampson County, NC',
 '20061': 'Geary County, KS',
 '37165': 'Scotland County, NC',
 '20063': 'Gove County, KS',
 '37167': 'Stanly County, NC',
 '36079': 'Putnam County, NY',
 '20069': 'Gray County, KS',
 '48351': 'Newton County, TX',
 '08069': 'Larimer County, CO',
 '08067': 'La Plata County, CO',
 '08065': 'Lake County, CO',
 '45081': 'Saluda County, SC',
 '08063': 'Kit Carson County, CO',
 '08061': 'Kiowa County, CO',
 '31119': 'Madison County, NE',
 '31113': 'Logan County, NE',
 '31111': 'Lincoln County, NE',
 '31117': 'McPherson County, NE',
 '31115': 'Loup County, NE',
 '48211': 'Hemphill County, TX',
 '08085': 'Montrose County, CO',
 '08087': 'Morgan County, CO',
 '18159': 'Tipton County, IN',
 '08081': 'Moffat County, CO',
 '26159': 'Van Buren County, MI',
 '08083': 'Montezuma County, CO',
 '18153': 'Sullivan County, IN',
 '18151': 'Steuben County, IN',
 '08089': 'Otero County, CO',
 '18157': 'Tippecanoe County, IN',
 '18155': 'Switzerland County, IN',
 '51117': 'Mecklenburg County, VA',
 '29119': 'McDonald County, MO',
 '29113': 'Lincoln County, MO',
 '29111': 'Lewis County, MO',
 '29117': 'Livingston County, MO',
 '29115': 'Linn County, MO',
 '51033': 'Caroline County, VA',
 '55063': 'La Crosse County, WI',
 '51031': 'Campbell County, VA',
 '54059': 'Mingo County, WV',
 '55065': 'Lafayette County, WI',
 '51037': 'Charlotte County, VA',
 '55103': 'Richland County, WI',
 '18007': 'Benton County, IN',
 '55101': 'Racine County, WI',
 '55107': 'Rusk County, WI',
 '55105': 'Rock County, WI',
 '51119': 'Middlesex County, VA',
 '51035': 'Carroll County, VA',
 '55069': 'Lincoln County, WI',
 '48055': 'Caldwell County, TX',
 '48363': 'Palo Pinto County, TX',
 '38059': 'Morton County, ND',
 '02122': 'Kenai Peninsula Borough, AK',
 '47025': 'Claiborne County, TN',
 '47023': 'Chester County, TN',
 '47021': 'Cheatham County, TN',
 '47029': 'Cocke County, TN',
 '29199': 'Scotland County, MO',
 '17037': 'DeKalb County, IL',
 '19179': 'Wapello County, IA',
 '39169': 'Wayne County, OH',
 '17039': 'De Witt County, IL',
 '19173': 'Taylor County, IA',
 '39163': 'Vinton County, OH',
 '19171': 'Tama County, IA',
 '39161': 'Van Wert County, OH',
 '19177': 'Van Buren County, IA',
 '39167': 'Washington County, OH',
 '19175': 'Union County, IA',
 '39165': 'Warren County, OH',
 '22027': 'Claiborne Parish, LA',
 '22025': 'Catahoula Parish, LA',
 '22023': 'Cameron Parish, LA',
 '22021': 'Caldwell Parish, LA',
 '22029': 'Concordia Parish, LA',
 '06007': 'Butte County, CA',
 '06005': 'Amador County, CA',
 '06003': 'Alpine County, CA',
 '06001': 'Alameda County, CA',
 '06009': 'Calaveras County, CA',
 '51620': 'Franklin city, VA',
 '02016': 'Aleutians West Census Area, AK',
 '02013': 'Aleutians East Borough, AK',
 '16011': 'Bingham County, ID',
 '39017': 'Butler County, OH',
 '16013': 'Blaine County, ID',
 '39015': 'Brown County, OH',
 '16015': 'Boise County, ID',
 '27159': 'Wadena County, MN',
 '16017': 'Bonner County, ID',
 '39011': 'Auglaize County, OH',
 '16019': 'Bonneville County, ID',
 '27155': 'Traverse County, MN',
 '27157': 'Wabasha County, MN',
 '27151': 'Swift County, MN',
 '27153': 'Todd County, MN',
 '22117': 'Washington Parish, LA',
 '21129': 'Lee County, KY',
 '21127': 'Lawrence County, KY',
 '48367': 'Parker County, TX',
 '21125': 'Laurel County, KY',
 '21123': 'Larue County, KY',
 '22115': 'Vernon Parish, LA',
 '21121': 'Knox County, KY',
 '16059': 'Lemhi County, ID',
 '46061': 'Hanson County, SD',
 '40001': 'Adair County, OK',
 '12039': 'Gadsden County, FL',
 '42031': 'Clarion County, PA',
 '46065': 'Hughes County, SD',
 '22111': 'Union Parish, LA',
 '46067': 'Hutchinson County, SD',
 '42035': 'Clinton County, PA',
 '12033': 'Escambia County, FL',
 '12031': 'Duval County, FL',
 '42039': 'Crawford County, PA',
 '12037': 'Franklin County, FL',
 '40003': 'Alfalfa County, OK',
 '12035': 'Flagler County, FL',
 '51133': 'Northumberland County, VA',
 '51131': 'Northampton County, VA',
 '51137': 'Orange County, VA',
 '51135': 'Nottoway County, VA',
 '40005': 'Atoka County, OK',
 '51139': 'Page County, VA',
 '16057': 'Latah County, ID',
 '31177': 'Washington County, NE',
 '40007': 'Beaver County, OK',
 '13299': 'Ware County, GA',
 '22119': 'Webster Parish, LA',
 '13291': 'Union County, GA',
 '13293': 'Upson County, GA',
 '13295': 'Walker County, GA',
 '51061': 'Fauquier County, VA',
 '13297': 'Walton County, GA',
 '12107': 'Putnam County, FL',
 '12105': 'Polk County, FL',
 '12103': 'Pinellas County, FL',
 '12101': 'Pasco County, FL',
 '02240': 'Southeast Fairbanks Census Area, AK',
 '12109': 'St. Johns County, FL',
 '26049': 'Genesee County, MI',
 '05029': 'Conway County, AR',
 '26041': 'Delta County, MI',
 '05021': 'Clay County, AR',
 '26043': 'Dickinson County, MI',
 '05023': 'Cleburne County, AR',
 '26045': 'Eaton County, MI',
 '05025': 'Cleveland County, AR',
 '26047': 'Emmet County, MI',
 '05027': 'Columbia County, AR',
 '20099': 'Labette County, KS',
 '48239': 'Jackson County, TX',
 '20091': 'Johnson County, KS',
 '20093': 'Kearny County, KS',
 '20095': 'Kingman County, KS',
 '20097': 'Kiowa County, KS',
 '13185': 'Lowndes County, GA',
 '13187': 'Lumpkin County, GA',
 '13181': 'Lincoln County, GA',
 '13183': 'Long County, GA',
 '01049': 'DeKalb County, AL',
 '13189': 'McDuffie County, GA',
 '12129': 'Wakulla County, FL',
 '36003': 'Allegany County, NY',
 '36005': 'Bronx County, NY',
 '36007': 'Broome County, NY',
 '36009': 'Cattaraugus County, NY',
 '45019': 'Charleston County, SC',
 '05115': 'Pope County, AR',
 '05117': 'Prairie County, AR',
 '05111': 'Poinsett County, AR',
 '05113': 'Polk County, AR',
 '48309': 'McLennan County, TX',
 '05119': 'Pulaski County, AR',
 '48435': 'Sutton County, TX',
 '48437': 'Swisher County, TX',
 '48431': 'Sterling County, TX',
 '48433': 'Stonewall County, TX',
 '48439': 'Tarrant County, TX',
 '53027': 'Grays Harbor County, WA',
 '48129': 'Donley County, TX',
 '48123': 'DeWitt County, TX',
 '30045': 'Judith Basin County, MT',
 '26029': 'Charlevoix County, MI',
 '48125': 'Dickens County, TX',
 '13071': 'Colquitt County, GA',
 '13073': 'Columbia County, GA',
 '13075': 'Cook County, GA',
 '13077': 'Coweta County, GA',
 '13079': 'Crawford County, GA',
 '13277': 'Tift County, GA',
 '13275': 'Thomas County, GA',
 '13273': 'Terrell County, GA',
 '13271': 'Telfair County, GA',
 '45087': 'Union County, SC',
 '45085': 'Sumter County, SC',
 '45083': 'Spartanburg County, SC',
 '13279': 'Toombs County, GA',
 '18099': 'Marshall County, IN',
 '18093': 'Lawrence County, IN',
 '18091': 'LaPorte County, IN',
 '18097': 'Marion County, IN',
 '18095': 'Madison County, IN',
 '27113': 'Pennington County, MN',
 '48057': 'Calhoun County, TX',
 '40099': 'Murray County, OK',
 '48053': 'Burnet County, TX',
 '48051': 'Burleson County, TX',
 '40093': 'Major County, OK',
 '40091': 'McIntosh County, OK',
 '40097': 'Mayes County, OK',
 '40095': 'Marshall County, OK',
 '20077': 'Harper County, KS',
 '20075': 'Hamilton County, KS',
 '37199': 'Yancey County, NC',
 '20073': 'Greenwood County, KS',
 '20071': 'Greeley County, KS',
 '37195': 'Wilson County, NC',
 '37197': 'Yadkin County, NC',
 '37191': 'Wayne County, NC',
 '37193': 'Wilkes County, NC',
 '20079': 'Harvey County, KS',
 '08079': 'Mineral County, CO',
 '48369': 'Parmer County, TX',
 '08071': 'Las Animas County, CO',
 '08073': 'Lincoln County, CO',
 '08075': 'Logan County, CO',
 '08077': 'Mesa County, CO',
 '18167': 'Vigo County, IN',
 '28021': 'Claiborne County, MS',
 '18165': 'Vermillion County, IN',
 '18163': 'Vanderburgh County, IN',
 '18161': 'Union County, IN',
 '28023': 'Clarke County, MS',
 '18169': 'Wabash County, IN',
 '08097': 'Pitkin County, CO',
 '08095': 'Phillips County, CO',
 '08093': 'Park County, CO',
 '08091': 'Ouray County, CO',
 '28025': 'Clay County, MS',
 '08099': 'Prowers County, CO',
 '29127': 'Marion County, MO',
 '48399': 'Runnels County, TX',
 '29125': 'Maries County, MO',
 '16023': 'Butte County, ID',
 '29123': 'Madison County, MO',
 '28027': 'Coahoma County, MS',
 '29121': 'Macon County, MO',
 '51595': 'Emporia city, VA',
 '20139': 'Osage County, KS',
 '29129': 'Mercer County, MO',
 '16025': 'Camas County, ID',
 '16027': 'Canyon County, ID',
 '35049': 'Santa Fe County, NM',
 '35045': 'San Juan County, NM',
 '35047': 'San Miguel County, NM',
 '35041': 'Roosevelt County, NM',
 '35043': 'Sandoval County, NM',
 '48391': 'Refugio County, TX',
 '48393': 'Roberts County, TX',
 '55139': 'Winnebago County, WI',
 '55137': 'Waushara County, WI',
 '20137': 'Norton County, KS',
 '55135': 'Waupaca County, WI',
 '55133': 'Waukesha County, WI',
 '55131': 'Washington County, WI',
 '31105': 'Kimball County, NE',
 '31107': 'Knox County, NE',
 '31101': 'Keith County, NE',
 '31103': 'Keya Paha County, NE',
 '31109': 'Lancaster County, NE',
 '37103': 'Jones County, NC',
 '47013': 'Campbell County, TN',
 '47011': 'Bradley County, TN',
 '47017': 'Carroll County, TN',
 '47015': 'Cannon County, TN',
 '47019': 'Carter County, TN',
 '39157': 'Tuscarawas County, OH',
 '19165': 'Shelby County, IA',
 '39155': 'Trumbull County, OH',
 '19167': 'Sioux County, IA',
 '27019': 'Carver County, MN',
 '19161': 'Sac County, IA',
 '39151': 'Stark County, OH',
 '19163': 'Scott County, IA',
 '27015': 'Brown County, MN',
 '27017': 'Carlton County, MN',
 '27011': 'Big Stone County, MN',
 '19169': 'Story County, IA',
 '27013': 'Blue Earth County, MN',
 '53011': 'Clark County, WA',
 '55009': 'Brown County, WI',
 '51041': 'Chesterfield County, VA',
 '55003': 'Ashland County, WI',
 '51580': 'Covington city, VA',
 '37109': 'Lincoln County, NC',
 '55007': 'Bayfield County, WI',
 '55005': 'Barron County, WI',
 '22031': 'De Soto Parish, LA',
 '22033': 'East Baton Rouge Parish, LA',
 '22035': 'East Carroll Parish, LA',
 '22037': 'East Feliciana Parish, LA',
 '22039': 'Evangeline Parish, LA',
 '06011': 'Colusa County, CA',
 '06013': 'Contra Costa County, CA',
 '06015': 'Del Norte County, CA',
 '06017': 'El Dorado County, CA',
 '06019': 'Fresno County, CA',
 '51630': 'Fredericksburg city, VA',
 '02068': 'Denali Borough, AK',
 '02060': 'Bristol Bay Borough, AK',
 '06087': 'Santa Cruz County, CA',
 '27129': 'Renville County, MN',
 '16003': 'Adams County, ID',
 '39021': 'Champaign County, OH',
 '16001': 'Ada County, ID',
 '39027': 'Clinton County, OH',
 '16007': 'Bear Lake County, ID',
 '39025': 'Clermont County, OH',
 '16005': 'Bannock County, ID',
 '27121': 'Pope County, MN',
 '27123': 'Ramsey County, MN',
 '16009': 'Benewah County, ID',
 '27125': 'Red Lake County, MN',
 '27127': 'Redwood County, MN',
 '48361': 'Orange County, TX',
 '21139': 'Livingston County, KY',
 '21131': 'Leslie County, KY',
 '21133': 'Letcher County, KY',
 '21135': 'Lewis County, KY',
 '21137': 'Lincoln County, KY',
 '12027': 'DeSoto County, FL',
 '12021': 'Collier County, FL',
 '12023': 'Columbia County, FL',
 '46115': 'Spink County, SD',
 '19087': 'Henry County, IA',
 '12029': 'Dixie County, FL',
 '46073': 'Jerauld County, SD',
 '42127': 'Wayne County, PA',
 '30081': 'Ravalli County, MT',
 '42009': 'Bedford County, PA',
 '46075': 'Jones County, SD',
 '06085': 'Santa Clara County, CA',
 '42005': 'Armstrong County, PA',
 '46079': 'Lake County, SD',
 '42003': 'Allegheny County, PA',
 '42001': 'Adams County, PA',
 '42121': 'Venango County, PA',
 '51125': 'Nelson County, VA',
 '42123': 'Warren County, PA',
 '51121': 'Montgomery County, VA',
 '48027': 'Bell County, TX',
 '46053': 'Gregory County, SD',
 '40069': 'Johnston County, OK',
 '48023': 'Baylor County, TX',
 '12111': 'St. Lucie County, FL',
 '12113': 'Santa Rosa County, FL',
 '12115': 'Sarasota County, FL',
 '12117': 'Seminole County, FL',
 '12119': 'Sumter County, FL',
 '40063': 'Hughes County, OK',
 '26059': 'Hillsdale County, MI',
 '17199': 'Williamson County, IL',
 '17197': 'Will County, IL',
 '26053': 'Gogebic County, MI',
 '17195': 'Whiteside County, IL',
 '26051': 'Gladwin County, MI',
 '17193': 'White County, IL',
 '26057': 'Gratiot County, MI',
 '17191': 'Wayne County, IL',
 '26055': 'Grand Traverse County, MI',
 '48209': 'Hays County, TX',
 '48203': 'Harrison County, TX',
 '40067': 'Jefferson County, OK',
 '41069': 'Wheeler County, OR',
 '48207': 'Haskell County, TX',
 '48205': 'Hartley County, TX',
 '17175': 'Stark County, IL',
 '17177': 'Stephenson County, IL',
 '17171': 'Scott County, IL',
 '40065': 'Jackson County, OK',
 '17173': 'Shelby County, IL',
 '01077': 'Lauderdale County, AL',
 '01075': 'Lamar County, AL',
 '17179': 'Tazewell County, IL',
 '01071': 'Jackson County, AL',
 '51141': 'Patrick County, VA',
 '48339': 'Montgomery County, TX',
 '48337': 'Montague County, TX',
 '48335': 'Mitchell County, TX',
 '48333': 'Mills County, TX',
 '48331': 'Milam County, TX',
 '48117': 'Deaf Smith County, TX',
 '48115': 'Dawson County, TX',
 '48113': 'Dallas County, TX',
 '48111': 'Dallam County, TX',
 '40153': 'Woodward County, OK',
 '40151': 'Woods County, OK',
 '48119': 'Delta County, TX',
 '36001': 'Albany County, NY',
 '48417': 'Shackelford County, TX',
 '48415': 'Scurry County, TX',
 '13089': 'DeKalb County, GA',
 '13085': 'Dawson County, GA',
 '13087': 'Decatur County, GA',
 '13081': 'Crisp County, GA',
 '13083': 'Dade County, GA',
 '26147': 'St. Clair County, MI',
 '13243': 'Randolph County, GA',
 '13241': 'Rabun County, GA',
 '13247': 'Rockdale County, GA',
 '13245': 'Richmond County, GA',
 '36101': 'Steuben County, NY',
 '13249': 'Schley County, GA',
 '48411': 'San Saba County, TX',
 '36105': 'Sullivan County, NY',
 '36107': 'Tioga County, NY',
 '34031': 'Passaic County, NJ',
 '48063': 'Camp County, TX',
 '48061': 'Cameron County, TX',
 '48067': 'Cass County, TX',
 '48065': 'Carson County, TX',
 '48069': 'Castro County, TX',
 '20043': 'Doniphan County, KS',
 '20041': 'Dickinson County, KS',
 '20047': 'Edwards County, KS',
 '20045': 'Douglas County, KS',
 '02275': 'Wrangell City and Borough, AK',
 '37187': 'Washington County, NC',
 '20049': 'Elk County, KS',
 '37185': 'Warren County, NC',
 '37183': 'Wake County, NC',
 '37181': 'Vance County, NC',
 '01095': 'Marshall County, AL',
 '01097': 'Mobile County, AL',
 '01091': 'Marengo County, AL',
 '34039': 'Union County, NJ',
 '01093': 'Marion County, AL',
 '01099': 'Monroe County, AL',
 '18171': 'Warren County, IN',
 '18173': 'Warrick County, IN',
 '18175': 'Washington County, IN',
 '18177': 'Wayne County, IN',
 '18179': 'Wells County, IN',
 '54035': 'Jackson County, WV',
 '54037': 'Jefferson County, WV',
 '54031': 'Hardy County, WV',
 '54033': 'Harrison County, WV',
 '54039': 'Kanawha County, WV',
 '29131': 'Miller County, MO',
 '29133': 'Mississippi County, MO',
 '29135': 'Moniteau County, MO',
 '29137': 'Monroe County, MO',
 '29139': 'Montgomery County, MO',
 '18085': 'Kosciusko County, IN',
 '18087': 'LaGrange County, IN',
 '18081': 'Johnson County, IN',
 '18083': 'Knox County, IN',
 '18089': 'Lake County, IN',
 '48097': 'Cooke County, TX',
 '31009': 'Blaine County, NE',
 '40119': 'Payne County, OK',
 '35059': 'Union County, NM',
 '31005': 'Arthur County, NE',
 '06083': 'Santa Barbara County, CA',
 '31007': 'Banner County, NE',
 '35055': 'Taos County, NM',
 '31001': 'Adams County, NE',
 '35053': 'Socorro County, NM',
 '31003': 'Antelope County, NE',
 '35051': 'Sierra County, NM',
 '06081': 'San Mateo County, CA',
 '45069': 'Marlboro County, SC',
 '40115': 'Ottawa County, OK',
 '55129': 'Washburn County, WI',
 '11001': 'District of Columbia, DC',
 '48099': 'Coryell County, TX',
 '55121': 'Trempealeau County, WI',
 '55123': 'Vernon County, WI',
 '55125': 'Vilas County, WI',
 '55127': 'Walworth County, WI',
 '28087': 'Lowndes County, MS',
 '28085': 'Lincoln County, MS',
 '28083': 'Leflore County, MS',
 '28081': 'Lee County, MS',
 '31179': 'Wayne County, NE',
 '28089': 'Madison County, MS',
 '48083': 'Coleman County, TX',
 '51079': 'Greene County, VA',
 '47009': 'Blount County, TN',
 '47005': 'Benton County, TN',
 '47007': 'Bledsoe County, TN',
 '47001': 'Anderson County, TN',
 '47003': 'Bedford County, TN',
 '19111': 'Lee County, IA',
 '39141': 'Ross County, OH',
 '19113': 'Linn County, IA',
 '39143': 'Sandusky County, OH',
 '19115': 'Louisa County, IA',
 '39145': 'Scioto County, OH',
 '19117': 'Lucas County, IA',
 '27009': 'Benton County, MN',
 '19119': 'Lyon County, IA',
 '27007': 'Beltrami County, MN',
 '27005': 'Becker County, MN',
 '27003': 'Anoka County, MN',
 '27001': 'Aitkin County, MN',
 '30097': 'Sweet Grass County, MT',
 '51077': 'Grayson County, VA',
 '49037': 'San Juan County, UT',
 '51057': 'Essex County, VA',
 '39153': 'Summit County, OH',
 '49035': 'Salt Lake County, UT',
 '51051': 'Dickenson County, VA',
 '49033': 'Rich County, UT',
 '02070': 'Dillingham Census Area, AK',
 '51053': 'Dinwiddie County, VA',
 '27139': 'Scott County, MN',
 '19029': 'Cass County, IA',
 '39039': 'Defiance County, OH',
 '16039': 'Elmore County, ID',
 '19025': 'Calhoun County, IA',
 '27133': 'Rock County, MN',
 '16035': 'Clearwater County, ID',
 '27131': 'Rice County, MN',
 '19021': 'Buena Vista County, IA',
 '27137': 'St. Louis County, MN',
 '19023': 'Butler County, IA',
 '27135': 'Roseau County, MN',
 '37139': 'Pasquotank County, NC',
 '51800': 'Suffolk city, VA',
 '51059': 'Fairfax County, VA',
 '12051': 'Hendry County, FL',
 '12053': 'Hernando County, FL',
 '12055': 'Highlands County, FL',
 '39159': 'Union County, OH',
 '12057': 'Hillsborough County, FL',
 '12059': 'Holmes County, FL',
 '42019': 'Butler County, PA',
 '46049': 'Faulk County, SD',
 '46047': 'Fall River County, SD',
 '42011': 'Berks County, PA',
 '46045': 'Edmunds County, SD',
 '42013': 'Blair County, PA',
 '46043': 'Douglas County, SD',
 '42015': 'Bradford County, PA',
 '46041': 'Dewey County, SD',
 '42017': 'Bucks County, PA',
 '51159': 'Richmond County, VA',
 '48347': 'Nacogdoches County, TX',
 '51153': 'Prince William County, VA',
 '51155': 'Pulaski County, VA',
 '51157': 'Rappahannock County, VA',
 '48345': 'Motley County, TX',
 '48343': 'Morris County, TX',
 '21097': 'Harrison County, KY',
 '21095': 'Harlan County, KY',
 '21093': 'Hardin County, KY',
 '21091': 'Hancock County, KY',
 '48341': 'Moore County, TX',
 '55001': 'Adams County, WI',
 '21099': 'Hart County, KY',
 '26067': 'Ionia County, MI',
 '05099': 'Nevada County, AR',
 '26065': 'Ingham County, MI',
 '26063': 'Huron County, MI',
 '26061': 'Houghton County, MI',
 '02261': 'Valdez-Cordova Census Area, AK',
 '26069': 'Iosco County, MI',
 '17189': 'Washington County, IL',
 '17181': 'Union County, IL',
 '17183': 'Vermilion County, IL',
 '17185': 'Wabash County, IL',
 '17187': 'Warren County, IL',
 '01069': 'Houston County, AL',
 '17165': 'Saline County, IL',
 '17163': 'St. Clair County, IL',
 '17161': 'Rock Island County, IL',
 '01061': 'Geneva County, AL',
 '01063': 'Greene County, AL',
 '01065': 'Hale County, AL',
 '01067': 'Henry County, AL',
 '49023': 'Juab County, UT',
 '48329': 'Midland County, TX',
 '54087': 'Roane County, WV',
 '48321': 'Matagorda County, TX',
 '48323': 'Maverick County, TX',
 '48325': 'Medina County, TX',
 '48327': 'Menard County, TX',
 '48101': 'Cottle County, TX',
 '48103': 'Crane County, TX',
 '48105': 'Crockett County, TX',
 '48107': 'Crosby County, TX',
 '48109': 'Culberson County, TX',
 '48459': 'Upshur County, TX',
 '13099': 'Early County, GA',
 '13097': 'Douglas County, GA',
 '13095': 'Dougherty County, GA',
 '13093': 'Dooly County, GA',
 '13091': 'Dodge County, GA',
 '48215': 'Hidalgo County, TX',
 '36119': 'Westchester County, NY',
 '13259': 'Stewart County, GA',
 '48213': 'Henderson County, TX',
 '13255': 'Spalding County, GA',
 '13257': 'Stephens County, GA',
 '13251': 'Screven County, GA',
 '13253': 'Seminole County, GA',
 '37097': 'Iredell County, NC',
 '48079': 'Cochran County, TX',
 '48075': 'Childress County, TX',
 '48077': 'Clay County, TX',
 '48071': 'Chambers County, TX',
 '48073': 'Cherokee County, TX',
 '24025': 'Harford County, MD',
 '53001': 'Adams County, WA',
 '24027': 'Howard County, MD',
 '24021': 'Frederick County, MD',
 '20059': 'Franklin County, KS',
 '24023': 'Garrett County, MD',
 '20055': 'Finney County, KS',
 '20057': 'Ford County, KS',
 ...}

In [5]:
PCPI_data.head()
# In units of dollars, not adjusted for inflation


Out[5]:
01001_PCPI 01003_PCPI 01005_PCPI 01007_PCPI 01009_PCPI 01011_PCPI 01013_PCPI 01015_PCPI 01017_PCPI 01019_PCPI ... 56027_PCPI 56029_PCPI 56031_PCPI 56033_PCPI 56035_PCPI 56037_PCPI 56039_PCPI 56041_PCPI 56043_PCPI 56045_PCPI
DATE
1970-01-01 3147 2900 2538 2355 2589 2161 2204 3038 2815 2475 ... 4000 3885 3758 4585 4492 3856 6305 3879 3598 3796
1971-01-01 3442 3264 2677 2627 2783 2384 2367 3405 3038 2692 ... 4601 4399 4003 5046 4734 4202 6914 4274 4104 4358
1972-01-01 3672 3577 3058 2894 3100 2749 2754 3809 3492 2957 ... 5524 4944 4390 5433 5303 5065 7168 4752 4299 5164
1973-01-01 4017 4163 3385 3174 3605 3185 3173 4114 3880 3426 ... 6084 5752 5264 6169 7129 6720 7823 5384 5194 5474
1974-01-01 4220 4614 3828 3522 3655 3344 3465 4567 4209 3559 ... 5225 6586 5430 7050 7944 7858 8624 5946 5631 5986

5 rows × 3049 columns


In [6]:
POP_data.head()
# In units of thousands


Out[6]:
01001_POP 01003_POP 01005_POP 01007_POP 01009_POP 01011_POP 01013_POP 01015_POP 01017_POP 01019_POP ... 56027_POP 56029_POP 56031_POP 56033_POP 56035_POP 56037_POP 56039_POP 56041_POP 56043_POP 56045_POP
DATE
1970-01-01 24.46 59.382 22.543 13.812 26.853 11.824 22.007 103.092 36.356 15.606 ... 2.924 17.752 6.486 17.852 3.755 18.391 4.823 7.1 7.569 6.307
1971-01-01 25.50 60.100 23.100 13.900 27.800 11.400 21.800 103.600 36.300 16.500 ... 2.900 18.000 6.700 17.900 3.600 19.200 5.200 7.0 7.500 6.100
1972-01-01 27.20 62.400 22.900 14.100 29.300 11.400 21.500 103.800 36.100 16.900 ... 2.900 18.200 6.600 18.300 3.800 21.400 5.700 7.2 7.900 6.100
1973-01-01 28.50 64.200 23.500 14.700 30.400 11.300 21.200 105.000 37.000 17.200 ... 2.900 18.300 6.800 18.900 3.700 22.900 6.200 7.2 7.800 6.100
1974-01-01 29.30 66.100 23.400 14.400 31.500 11.100 21.200 105.900 37.500 17.700 ... 2.800 18.400 7.000 19.200 3.700 27.000 6.900 7.8 7.800 6.000

5 rows × 3049 columns

Let's transform the data into something a bit more manageable:


In [7]:
# Normalize PCPI values to 2015 USD and convert to units of thousands
PCPI_norm  = analysis.deflate_mod(PCPI_data/1e3, norm_filename='CPIAUCSL.csv', base='2015')

# Take logarithm of POP data, then convert from thousands (add 3)
POP_log = POP_data.apply(np.log10) + 3

Now we can do all kinds of cool things. Let's start with just plotting the data from the first year (1970) and the last (2013):


In [8]:
year1 = '1970'
year2 = '2013'

f = figure(width = 900, height = 540, x_range=[0, 100], y_range=[0, 8], title='PCPI vs POP', \
           x_axis_label='Per Capita Personal Income (2015 Dollars, Thousands)', y_axis_label='Log County Population')
f.circle(PCPI_norm[year1].values[0], POP_log[year1].values[0], alpha=0.1, color='royalblue', legend=year1)
f.circle(PCPI_norm[year2].values[0], POP_log[year2].values[0], alpha=0.1, color='firebrick', legend=year2)
show(f)


Let's look at some individual counties over time. First, we'll invert the counties dictionary to make it more human-friendly:


In [9]:
# Double check that the names of counties uniquely identify each position
# (otherwise we'll have errors which won't raise exceptions)
len(set(counties.keys())) == len(set(counties.values()))


Out[9]:
True

In [10]:
# We're in the clear, so let's invert the dictionary
counties_inv = {name : FIPS for FIPS, name in counties.items()}

# and test it out
print counties_inv['Hennepin County, MN']
print counties[counties_inv['Hennepin County, MN']]


27053
Hennepin County, MN

Now we can easily look up individual counties by name:


In [11]:
names = [
    'Hennepin County, MN',
    'New York County, NY',
    'Los Angeles County, CA'
]

colors = [
    'royalblue',
    'firebrick',
    'forestgreen'
]

f1 = figure(width = 900, height = 540, x_range=[1970, 2013], title='PCPI for counties in which the author has lived',\
           x_axis_label='Year', y_axis_label='PCPI (2015 Dollars, Thousands)')

f2 = figure(width = 900, height = 540, x_range=f1.x_range, title='Population of counties in which the author has lived',\
           x_axis_label='Year', y_axis_label='Log County Population')

x = PCPI_norm.index.year

for color, name in zip(colors, names):
    FIPS = counties_inv[name]
    f1.line(x, PCPI_norm[FIPS+'_PCPI'], color=color, legend=name)
    f2.line(x, POP_log[FIPS+'_POP'], color=color, legend=name)

f = gridplot([[f1], [f2]])
show(f)


Let's take a look at all counties in a single state:


In [12]:
state = 'MN'
counties_in_state = [name for name in counties_inv.keys() if name.split(',')[1].strip() == state]

f = figure(width = 900, height = 540, x_range=[1970, 2013], y_range=[0, 100], title='PCPI in '+state, \
           x_axis_label='Year', y_axis_label='PCPI (2015 Dollars, Thousands)')

for c in counties_in_state:
    try:
        column_name = counties_inv[c]+'_PCPI'
        f.line(PCPI_norm.index.year, PCPI_norm[column_name].values)
    except KeyError:
        pass
    
show(f)


Looks cool, but it's a little unwieldy. Let's compare just the 10 most populous counties and the national average:


In [13]:
# first, let's get a list of FIPS codes with valid data so that we dont raise KeyErrors
valid_FIPS = [col[:5] for col in POP_data.columns]

In [14]:
n = 10 # if using brewer below, n must be between 2 and 10

state = 'MN'
counties_in_state = [name for name in counties_inv.keys() if name.split(',')[1].strip() == state]

# Let's make a dataframe from the POP_log dataframe which only has the state of interest
# and then take the n highest populated counties at 2013
FIPS_in_state = [FIPS for FIPS, name in counties.items() if name.split(',')[1].strip() == state]
top = POP_log[[FIPS+'_POP' for FIPS in FIPS_in_state if FIPS in valid_FIPS]]['2013'].max().sort_values(ascending=False).index[:n]

# Let's make another new dataframe, this time for PCPI
# We want the top n counties and the national average
top_PCPI = PCPI_norm[[top_i[:5]+'_PCPI' for top_i in top]]
top_PCPI.columns = [counties[colname[:5]] for colname in top_PCPI.columns] # renaming is easier before we add natl_avg
natl_avg = PCPI_norm.mean(axis = 1)
natl_avg.name = "National Average"
top_PCPI = top_PCPI.join(natl_avg)

# We'll sort the data by the maximum PCPI, so data will be ordered
# in legend and coloring by highest to lowest
cols_in_order = top_PCPI.max().sort_values(ascending=False).index
x  = top_PCPI.index.year
colors = brewer['Spectral'][n+1][::-1]

fig_title = 'PCPI of {} most populous counties in {}'.format(n, state)
f = figure(width = 900, height = 540, x_range=[1970, 2013], y_range=[0, 100], title=fig_title, \
           x_axis_label='Year', y_axis_label='PCPI (2015 Dollars, Thousands)')

for color, column in zip(colors, cols_in_order):
    f.circle(x, top_PCPI[column].values, fill_color=color, line_color='black', size=8, legend=column)

    
f.legend.orientation = 'top_left'


show(f)


To better assess comparative economic growth, lets normalize the PCPI of each county (and the national average) to the value for each at 1970:


In [15]:
n = 10 # if using brewer below, n must be between 2 and 10

state = 'MN'
counties_in_state = [name for name in counties_inv.keys() if name.split(',')[1].strip() == state]

# Let's make a dataframe from the POP_log dataframe which only has the state of interest
# and then take the n highest populated counties at 2013
FIPS_in_state = [FIPS for FIPS, name in counties.items() if name.split(',')[1].strip() == state]
top = POP_log[[FIPS+'_POP' for FIPS in FIPS_in_state if FIPS in valid_FIPS]]['2013'].max().sort_values(ascending=False).index[:n]

# Let's make another new dataframe, this time for PCPI
# We want the top n counties and the national average
top_PCPI = PCPI_norm[[top_i[:5]+'_PCPI' for top_i in top]]
top_PCPI.columns = [counties[colname[:5]] for colname in top_PCPI.columns] # renaming is easier before we add natl_avg
natl_avg = PCPI_norm.mean(axis = 1)
natl_avg.name = "National Average"
top_PCPI = top_PCPI.join(natl_avg)

# We'll sort the data by the maximum PCPI, so data will be ordered
# in legend and coloring by highest to lowest
cols_in_order = top_PCPI.max().sort_values(ascending=False).index
x  = top_PCPI.index.year
colors = brewer['Spectral'][n+1][::-1]

fig_title = 'Growth of mean income in {} most populous counties in {}'.format(n, state)
f = figure(width = 900, height = 540, x_range=[1970, 2013], y_range=[0, 2.5], title=fig_title, \
           x_axis_label='Year', y_axis_label='Normalized Income Growth since 1970')

for color, column in zip(colors, cols_in_order):
    y = top_PCPI[column].values / top_PCPI[column].values[0]
    f.circle(x, y, fill_color=color, line_color='black', size=8, legend=column)

    
f.legend.orientation = 'bottom_right'


show(f)


Looks like Ramsey County (home of St. Paul) fared worse after the 2008 financial crisis than the other major counties in Minnesota.

Let's return to the first plot of PCPI for counties in Minnesota:

What is going on with that huge spike at 1973? It doesn't happen for any of the 10 most populous counties.


In [16]:
state = 'MN'
counties_in_state = [name for name in counties_inv.keys() if name.split(',')[1].strip() == state]

f = figure(width = 900, height = 540, x_range=[1971, 1975], y_range=[0, 60], title='PCPI in '+state, \
           x_axis_label='Year', y_axis_label='PCPI (2015 Dollars, Thousands)')

for c in counties_in_state:
    try:
        column_name = counties_inv[c]+'_PCPI'
        f.line(PCPI_norm.index.year, PCPI_norm[column_name].values)
    except KeyError:
        pass
    
show(f)


Let's get a list of counties, sorted by their proportional growth at 1973, and see if there are some unifying properties...


In [17]:
state = 'MN'
FIPS_in_state = [FIPS for FIPS, name in counties.items() if name.split(',')[1].strip() == state]

in_state = PCPI_norm[[FIPS+'_PCPI' for FIPS in FIPS_in_state]]
in_state.columns = [counties[colname[:5]] for colname in in_state.columns]
natl_avg = PCPI_norm.mean(axis = 1)
natl_avg.name = "National Average"
in_state = in_state.join(natl_avg)

growth = in_state.diff() / in_state

# convert single row from in_state to series
growth['1973'].squeeze().sort_values(ascending=False)


Out[17]:
Wilkin County, MN               0.561134
Traverse County, MN             0.527813
Norman County, MN               0.498140
Grant County, MN                0.472420
Kittson County, MN              0.404819
Mahnomen County, MN             0.403213
Marshall County, MN             0.399852
Red Lake County, MN             0.394426
Swift County, MN                0.387792
Big Stone County, MN            0.373965
Lac qui Parle County, MN        0.332064
Stevens County, MN              0.317108
Renville County, MN             0.309517
Yellow Medicine County, MN      0.294413
Pope County, MN                 0.285447
Polk County, MN                 0.284057
Jackson County, MN              0.265156
Faribault County, MN            0.263743
Lake of the Woods County, MN    0.261871
Murray County, MN               0.259973
Redwood County, MN              0.257752
Roseau County, MN               0.254778
Martin County, MN               0.239604
Chippewa County, MN             0.236855
Sibley County, MN               0.232763
Watonwan County, MN             0.226638
Rock County, MN                 0.226107
Waseca County, MN               0.218363
Lincoln County, MN              0.215967
Clay County, MN                 0.192783
                                  ...   
Mower County, MN                0.090114
Stearns County, MN              0.090044
Scott County, MN                0.088320
Mille Lacs County, MN           0.084931
Houston County, MN              0.081979
Rice County, MN                 0.079471
Chisago County, MN              0.075312
Sherburne County, MN            0.073163
Isanti County, MN               0.072040
Beltrami County, MN             0.072011
Winona County, MN               0.069886
Cass County, MN                 0.068396
Kanabec County, MN              0.064902
Carlton County, MN              0.064595
Olmsted County, MN              0.063503
Wright County, MN               0.056261
Cook County, MN                 0.053824
Itasca County, MN               0.051123
Pine County, MN                 0.047887
Benton County, MN               0.046885
Hennepin County, MN             0.045475
Crow Wing County, MN            0.044396
Koochiching County, MN          0.042998
Carver County, MN               0.041306
St. Louis County, MN            0.037158
Lake County, MN                 0.030449
Dakota County, MN               0.028359
Washington County, MN           0.026879
Ramsey County, MN               0.023200
Anoka County, MN                0.016977
Name: 1973-01-01 00:00:00, dtype: float64

It seems that those counties which had the greatest proportional growth in 1973 are also among the highest producers of corn in the state. 1973 was also when oil prices rose to excessive levels. This sudden increase in income may reflect an increased demand for corn, which is used to produce ethanol that in turn is used as diluent for gasoline. As oil becomes more expensive, it makes sense that lower grades of gasoline would be in higher demand, and thus more ethanol would be needed to produce it.