我正在参加有关数据科学的在线课程(以丰富自己的技能)。这是本课程要交的最后一个项目
当前的请求是制作一个choropleth映射。
这是我的代码
!conda install -c conda-forge folium=0.5.0 --yes
import folium
!wget --quiet https://ibm.box.com/shared/static/cto2qv7nx6yq19logfcissyy4euo8lho.json
-O world_countries.json sfgeo=r'world_countries.json'
sfmap=folium.Map(location=[37.77986,-122.42905],zoom_start=12)
threshold_scale = np.linspace(df1_count['Count'].min(), df1_count['Count'].max(), 6, dtype=int)
threshold_scale = threshold_scale.tolist()
sfmap.choropleth(geo_data=sfgeo,
data=df1_count,
columns=['PdDistrict','Count'],
bins = threshold_scale,
key_on='feature.properties.name',
fill_color = 'YlOrRd',
fill_opacity = 0.7,
line_opacity=0.2,
legend_name='Rate'
)
sfmap
报告的错误如下
TypeError Traceback (most recent call last)
<ipython-input-75-1f74ef523c22> in <module>
13 fill_opacity = 0.7,
14 line_opacity=0.2,
---> 15 legend_name='Rate'
16 )
17
TypeError: choropleth() got an unexpected keyword argument 'bins'
为了便于记录并易于理解,这是我的df1_count数据框(由于有人可能“窃取”此信息而被删除,这意味着我违反了课程的代码)
谢谢您的协助
尝试一下。
folium.Choropleth(geo_data=sfgeo,
data=df1_count,
columns=['PdDistrict','Count'],
bins = threshold_scale,
key_on='feature.properties.name',
fill_color = 'YlOrRd',
fill_opacity = 0.7,
line_opacity=0.2,
legend_name='Rate'
).add_to(sfmap)