Issues with Folium Choropleth Mapping Example
Question: I am trying to create a choropleth map using folium, following the example
here: <https://pypi.python.org/pypi/folium>. The goal is to produce a
choropleth map of US unemployment rates, but when I open my map US states are
not shaded in. Any suggestions?

    
    
    import folium
    import pandas as pd
    
    state_geo = r'data/us-states.json'
    state_unemployment = r'data/US_Unemployment_Oct2012.csv'
    
    state_data = pd.read_csv(state_unemployment)
    
    #Let Folium determine the scale
    map = folium.Map(location=[48, -102], zoom_start=3)
    map.geo_json(geo_path=state_geo, data=state_data,
                 columns=['State', 'Unemployment'],
                 key_on='feature.id',
                 fill_color='YlGn', fill_opacity=0.7, line_opacity=0.2,
                 legend_name='Unemployment Rate (%)')
    map.create_map(path='us_states.html')
    

Thanks,


Answer: I think the issue is a mis-match of column names:

1) data=state_data has columns ['State', 'Unemployment'] 2) if you open us-
states.json, you will find key_on='feature.id' corresponds to '01', '02' and
so on..

In folium key_on is suppose to match the first column of data, in this case
'State'.

But '01', '02' ..doesn't fit 'State' column which has 'AL', 'AK', 'AZ'..

If you could come up with key_on in us-states.json that matches 'States'
columns, I think it should solve your problem.

Note: I am assuming us-states.json is from
<https://raw.githubusercontent.com/alignedleft/d3-book/master/chapter_12/us-
states.json> and US_Unemployment_Oct2012.csv from
<https://raw.githubusercontent.com/python-
visualization/folium/master/examples/US_Unemployment_Oct2012.csv>

