Search code examples
jsonpandasjupyter-notebookfoliumchoropleth

folium blank choropleth map on jupyter, possible JSON format issue


I've been actively trying to figure out why I get a blank map in on my Jupyter notebook when trying to generate a choropleth map on folium. This is also my 1st post as I am fairly new to programming.

From searching online resources, the most common problem is an incorrect key_on usage, however I do not believe this is the case, it might be an incorrect JSON format vs folium(epsg=4326).

https://raw.githubusercontent.com/CyperPunk001/Immigration-to-CA-from-RSA/master/canada_provinces.geojson This is the JSON file from my github repository I am using for my notebook, I am not sure what format this is?

Canada COVID 19 cases This is the current dataframe I am using on my notebook for folium.

folium code for choropleth map This is the current folium code I am using to generate a choropleth map of active COVID 19 cases vs province/territory. Problem is that I get a blank map each time.

What I have tried so far:

  1. Import Json and replace my dataframe "prname" column names with the actual Json feature.properties.name province/territory name. This did not fix my problem.

  2. Rename "prname" to "name". THis did not fix my problem.

  3. Check to see if the dtype of the columns "name", "numactive" is of correct type, this checks out so can't be he problem? dtypes of dataframe

  4. This lead me to see if maybe the JSON file I imported has an incompatible format vs folium, so I tried to import geopandas, or rather install but alas I am getting constant import errors as well. I have tried all the lines of code with no luck. geopandas conda install

current folium version 0.11.0

Any help would be greatly appreciated.


Solution

  • I have managed to solve the answer - seems as though because the title was in double quotes and not single, the map displayed blank. After a simple change the map displays perfectly! Just shows how a little missed detail like that can cause...

    Before: See above example of folium code.

    After:

    m = folium.Map(location=[56.130, -106.35],zoom_start=3.5, tiles = "Mapbox Bright")
    m.choropleth(
     geo_data=world_geo,
     name='choropleth',
     data=can_cov_yes_df,
     columns=['name', 'numactive'],
     key_on='feature.properties.name',
     fill_color='YlOrRd',
     threshold_scale=threshold_scale,
     fill_opacity=0.7,
     line_opacity=0.2,
     legend_name='Active Cases in Canadadian provinces'
    )
    folium.LayerControl().add_to(m)
    m
    

    Now the map displays:

    choroplet map