小叶中的Choropleth:在上找不到键

2024-04-19 19:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我有地理json格式的边界

{'type': 'FeatureCollection',
 'features': [{'type': 'Feature',
   'properties': {'STATEFP10': '04',
    'ZCTA5CE10': '85347'},
   'geometry': {'type': 'Polygon',
    'coordinates': [[[-113.587371, 32.77836],
      [-113.587269, 32.77819],
      [-113.590707, 32.776887],
     ...

我还有一些数据

data

POSTCODE    X
0   85347   0
1   85356   0

我正试图策划一个基本的合唱团。 如果我这样做,我会得到

AttributeError: 'NoneType' object has no attribute 'get'

以下代码段中有什么错误?这是一个复制粘贴的示例。。。 我已经确保边界键和数据帧邮政编码完全相同

m = folium.Map( zoom_start=8)
# Add the color for the chloropleth:
folium.Choropleth(
 geo_data=boundaries,
 name='choropleth',
 data=data,
 columns=['POSTCODE','X'],
 key_on='features.properties.ZCTA5CE10',
 fill_color='BuPu',
#fill_opacity=0.7
).add_to(m)
folium.LayerControl().add_to(m)
m

Tags: theto数据adddatatypepropertiesfill
1条回答
网友
1楼 · 发布于 2024-04-19 19:29:29

为参数feature.properties.ZCTA5CE10上的键_尝试功能而不是功能

来自Choroplethdocstring

key_on: string, default None Variable in the geo_data GeoJSON file to bind the data to. Must start with 'feature' and be in JavaScript objection notation. Ex: 'feature.id' or 'feature.properties.statename'.

相关问题 更多 >