【发布时间】:2019-06-09 09:36:03
【问题描述】:
我一直在使用 Folium Choropleth Maps 绘制显示旧金山不同社区犯罪率的地图。
我使用的geojson文件是: https://cocl.us/sanfran_geojson 我已将其保存为“数据”
我使用的数据来自: 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'
非常感谢您的帮助,谢谢!
【问题讨论】:
-
你能提供完整的堆栈跟踪吗? “unhashable type: 'list'”可能是由于几个原因。
-
您收到的警告告诉您应该使用类
Chorophlet而不是方法chorophlet。检查此link 以了解如何执行此操作:转到“使用 Chorophlet 类”部分(单元格In [15])
标签: python dictionary choropleth folium