Folium Choropleth + GeoJSON raises AttributeError: 'NoneType'

后端 未结 2 1472
我在风中等你
我在风中等你 2020-12-18 06:47

I\'m trying to do a choropleth using folium which offers a great link between GeoJSON, Pandas and leaflet.

GeoJSON format is like below :

{
  \"type         


        
相关标签:
2条回答
  • 2020-12-18 07:32

    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.

    0 讨论(0)
  • 2020-12-18 07:50

    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.

    0 讨论(0)
提交回复
热议问题