folium 0.4 cannot work : TypeError: choropleth() got an unexpected keyword argument 'geo_path'

4.7k views Asked by At

I am reading Alexander T. Combs 's book- Python Machine Learning Blueprints: Intuitive data projects you can relate to.

There are some questions on ch2.The code on the book:

map = folium.Map(location=[40.748817, -73.985428], zoom_start=13)
map.geo_json(geo_path=r'/Users/alexcombs/Downloads/nyc.json', data=su_lt_two,
             columns=['Zip', 'Rent'],
             key_on='feature.properties.postalCode',
             threshold_scale=[1700.00, 1900.00, 2100.00, 2300.00, 2500.00, 2750.00],
             fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.2,
             legend_name='Rent (%)',
              reset=True)
map.create_map(path='nyc.html')

My code:

map = folium.Map(location=[40.748817, -73.985428], zoom_start=13)

nyc = r'nyc.json'

map.choropleth(geo_path = nyc, data=su_lt_two,columns=['zip', 'Rent'],
               key_on='Feature.properties.postalCode',
               threshold_scale=[1700.00, 1900.00, 2100.00, 2300.00, 2500.00, 2750.00],
               fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.2,
               legend_name='Rent (%)',reset=True)

map.create_map(path='nyc.html')

and I got a Typeerror:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-129-420abe6d80fb> in <module>()
      8                threshold_scale=[1700.00, 1900.00, 2100.00, 2300.00, 2500.00, 2750.00],
      9                fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.2,
---> 10                legend_name='Rent (%)',reset=True)
     11 
     12 map.create_map(path='nyc.html')

TypeError: choropleth() got an unexpected keyword argument 'geo_path'

nyc.json file

1

There are 1 answers

0
Bob Haffner On

There were some api changes with 0.4.

Here's the one that causing your error

  • choropleth now takes a single geo_data instad of geo_path/geo_str leaving the parsing to GeoJSON

Try this

map.choropleth(geo_data = nyc, data=su_lt_two,columns=['zip', 'Rent'],
               key_on='Feature.properties.postalCode',
               threshold_scale=[1700.00, 1900.00, 2100.00, 2300.00, 2500.00, 2750.00],
               fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.2,
               legend_name='Rent (%)',reset=True)