2

我正在阅读 Alexander T. Combs 的书 - Python 机器学习蓝图:您可以关联的直观数据项目。

ch2有一些问题。书上的代码:

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')

我的代码:

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')

我得到了一个类型错误:

---------------------------------------------------------------------------
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 文件

4

1 回答 1

3

0.4有一些api 更改

这是导致您的错误的原因

  • choropleth现在需要一个geo_datainstad geo_path/geo_str 将解析留给GeoJSON

尝试这个

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)
于 2017-09-09T03:41:24.570 回答