Folium Choropleth + GeoJSON raises AttributeError: 'NoneType'

左心房为你撑大大i 提交于 2019-11-29 07:35:05

There were 2 problems :

1 - The correct access to 'insee' parameters is : key_on='feature.properties.insee'

The best way to find the right key_on is to play with the geoJSON dict to make sure you are calling the right properties.

2- Once you have the right key_on parameters, you need to make sure that all the available keys in the geoJSON are contained in your Pandas DataFrame (otherwise it will raise a KeyError)

In this case, I used the following command line to get all the insee keys contained by my geoJSON:

ogrinfo -ro -al communes-20150101-100m.shp -geom=NO | grep insee > list_code_insee.txt

If you are experiencing the same issue, this should solve your problem.

I had the same problem on JupyterLab (on labs.cognitiveclass.ai) using Folium 0.5.0. Then I copied my code and ran it in PyCharm, and it worked! I don't understand why, perhaps there is some backend issue (?)

If you want to display a folium map outside of a Jupyter notebook, you have to save the map to html:

map_france.save('map_france.html')

and open the html in your browser.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!