我正在尝试为印度各州人口绘制一个choropleth地图。这是我的代码:
india_geo=r'e:/coursera/indiageo.geojson
world_map=folium.Map(location=[20.5937,78.9629],zoom_start=4)
folium.Choropleth(
geo_data=india_geo.geojson,
data=df_pop,
key_on='features.properties.ID_1',
columns=['Name', 'TOT_P'],
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Distribution'
).add_to(world_map)
folium.LayerControl().add_to(world_map)
world_map
问题是当我运行代码时,我的屏幕白屏了。我的数据框由州名及其人口组成:
Name TOT_P
0 JAMMU & KASHMIR 1493299
1 HIMACHAL PRADESH 392126
2 UTTARAKHAND 291903
3 RAJASTHAN 9238534
4 UTTAR PRADESH 1134273
到geojson文件的链接如下:
https://raw.githubusercontent.com/geohacker/india/master/district/india_district.geojson
答案 0 :(得分:0)
您需要在'id'上添加功能才能访问功能
with open(r'\india.GEOJSON') as f:
geojson_counties = json.load(f)
for i in geojson_counties['features']:
i['id'] = i['properties']['NAME_1']
并将key_on设置为
key_on='feature.id'