:我一直在制作一张地图,用来显示旧金山不同社区的犯罪率。
我使用的geojson文件是:https://cocl.us/sanfran_geojson,我已将其另存为'data‘
我使用的数据来自:https://cocl.us/sanfran_crime_dataset,我将其保存为'cdata‘。
我的代码如下;
cdata.rename(columns={'PdDistrict':'Neighbourhood'}, inplace=True)
neighbourhood = cdata.groupby(['Neighbourhood']).size().reset_index(name='Count')
要获得以下信息:
Neighbourhood Count
0 BAYVIEW 14303
1 CENTRAL 17666
2 INGLESIDE 11594
3 MISSION 19503
4 NORTHERN 20100
5 PARK 8699
6 RICHMOND 8922
7 SOUTHERN 28445
8 TARAVAL 11325
9 TENDERLOIN 9942
然后我使用:
sanfran = folium.Map(location=[37.7749, -122.4194], zoom_start = 12)
sanfran.choropleth(
geo_data=dat,
name='choropleth',
data=neighbourhood,
columns=['Neighbourhood', 'Count'],
key_on='properties.DISTRICT',
fill_color='YlOrRd',
fill_opacity = 0.7,
line_opacity=0.2,
legend_name='Crime Rate in San Francisco')
当我运行sanfran.choropleth代码时,我得到以下错误:
C:\ProgramData\Anaconda3\lib\site-packages\folium\folium.py:432: FutureWarning: The choropleth method has been deprecated. Instead use the new Choropleth class, which has the same arguments. See the example notebook 'GeoJSON_and_choropleth' for how to do this.
FutureWarning
然后,如果我只输入'sanfran‘并运行我得到的代码:
unhashable type: 'list'
非常感谢您对此的帮助,谢谢!
发布于 2019-06-10 03:05:04
语法发生了变化。
在folium和链'add_to( map )‘方法上使用大写'C’调用Choropleth,如下所示传递地图名称
folium.Choropleth(all your arguments as the old method).add_to(map)
检查此链接,并向下滚动到Choropleth地图上的部分以获取详细信息。https://python-visualization.github.io/folium/quickstart.html#Getting-Started
发布于 2020-02-03 22:30:56
如果你想运行并创建一个map,你应该遵循folium的新语法。你的代码应该是这样的:
sanfran = folium.Map(location=[37.7749, -122.4194], zoom_start=12)
folium.Choropleth(
geo_data=dat,
name='choropleth',
data=neighbourhood,
columns=['Neighbourhood', 'Count'],
key_on='properties.DISTRICT',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Crime Rate in San Francisco').add_to(sanfran)
sanfran.save('outfile.html')
https://stackoverflow.com/questions/54197756
复制相似问题