'''
Choropleth maps of US counties.

GeoJSON via the US Census and Eric Celeste:

http://eric.clst.org/Stuff/USGeoJSON

'''

import folium
import pandas as pd

county_data = r'us_county_data.csv'
county_geo = r'us_counties_20m_topo.json'

# Read into Dataframe, cast to string for consistency.
df = pd.read_csv(county_data, na_values=[' '])
df['FIPS_Code'] = df['FIPS_Code'].astype(str)


def set_id(fips):
    '''Modify FIPS code to match GeoJSON property'''
    if fips == '0':
        return None
    elif len(fips) <= 4:
        return ''.join(['0500000US0', fips])
    else:
        return ''.join(['0500000US', fips])

# Apply set_id, drop NaN.
df['GEO_ID'] = df['FIPS_Code'].apply(set_id)
df.dropna(subset=['GEO_ID'], inplace=True)

# Number of employed with auto scale.
map_1 = folium.Map(location=[48, -102], zoom_start=3)
map_1.choropleth(geo_path=county_geo, data_out='data1.json', data=df,
                 columns=['GEO_ID', 'Employed_2011'],
                 key_on='feature.id',
                 fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.3,
                 topojson='objects.us_counties_20m')
map_1.save(outfile='map_1.html')

# Unemployment with custom defined scale.
map_2 = folium.Map(location=[40, -99], zoom_start=4)
map_2.choropleth(geo_path=county_geo, data_out='data2.json', data=df,
                 columns=['GEO_ID', 'Unemployment_rate_2011'],
                 key_on='feature.id',
                 threshold_scale=[0, 5, 7, 9, 11, 13],
                 fill_color='YlGnBu', line_opacity=0.3,
                 legend_name='Unemployment Rate 2011 (%)',
                 topojson='objects.us_counties_20m')
map_2.save(outfile='map_2.html')

# Median Household income.
map_3 = folium.Map(location=[40, -99], zoom_start=4)
map_3.choropleth(geo_path=county_geo, data_out='data3.json', data=df,
                 columns=['GEO_ID', 'Median_Household_Income_2011'],
                 key_on='feature.id',
                 fill_color='PuRd', line_opacity=0.3,
                 legend_name='Median Household Income 2011 ($)',
                 topojson='objects.us_counties_20m')
map_3.save(outfile='map_3.html')

@@ -831,26 +831,24 @@
 )%0Amap_1.
-choropleth
+geo_json
 (geo_pat
@@ -900,34 +900,32 @@
 %0A               
-  
 columns=%5B'GEO_ID
@@ -937,34 +937,32 @@
 mployed_2011'%5D,%0A
-  
                k
@@ -988,34 +988,32 @@
 %0A               
-  
 fill_color='YlOr
@@ -1045,34 +1045,32 @@
 ne_opacity=0.3,%0A
-  
                t
@@ -1239,26 +1239,24 @@
 )%0Amap_2.
-choropleth
+geo_json
 (geo_pat
@@ -1308,34 +1308,32 @@
 %0A               
-  
 columns=%5B'GEO_ID
@@ -1369,34 +1369,32 @@
 %0A               
-  
 key_on='feature.
@@ -1413,18 +1413,16 @@
         
- 
- 
 threshol
@@ -1451,18 +1451,16 @@
 1, 13%5D,%0A
-  
         
@@ -1512,34 +1512,32 @@
 %0A               
- 
- 
 legend_name='Une
@@ -1558,26 +1558,24 @@
  2011 (%25)',%0A
-  
             
@@ -1737,18 +1737,16 @@
 p_3.
-choropleth
+geo_json
 (geo
@@ -1802,34 +1802,32 @@
 %0A               
- 
- 
 columns=%5B'GEO_ID
@@ -1869,34 +1869,32 @@
 %0A               
-  
 key_on='feature.
@@ -1890,34 +1890,32 @@
 n='feature.id',%0A
-  
                f
@@ -1957,34 +1957,32 @@
 %0A               
-  
 legend_name='Med
@@ -2009,26 +2009,24 @@
  2011 ($)',%0A
-  
             

Revert "Fix PEP8 formatting"