Unable to get Choropleth Map using my code: Please guide Thanks

Viewed 5167

Im getting this error : The choropleth method has been deprecated. Instead use the new Choropleth class, which has the same arguments. See the example notebook 'GeoJSON_and_choropleth' for how to do this.

with open('C:/Users/abcdef/Desktop/world_countries.json') as data_file:
    data = json.load(data_file)

world_geo = data
world_map = folium.Map(location=[0, 0], zoom_start=2, tiles = 'Mapbox Bright')
world_map.choropleth(
    geo_data = world_geo,
    data = canadamap,
    columns = ['Country', 'Total'],
    key_on = 'feature.properties.name',
    fill_color = 'YlOrRd', 
    fill_opacity = 0.7, 
    line_opacity = 0.2,
    legend_name = 'Immigration to Canada'
)

world_map

I'm not getting Choropleth Map using the above code; instead I'm getting

The choropleth method has been deprecated. Instead use the new Choropleth class, which has the same arguments. See the example notebook 'GeoJSON_and_choropleth' for how to do this.

1 Answers

This should work for you. The method has been modified to Choropleth and not choropleth. You should have

folium.Choropleth(args*).add_to(world_map) 

In all

world_geo = r'world_countries.json' # geojson file

    # create a plain world map
world_map = folium.Map(location=[0, 0], zoom_start=2, tiles='Mapbox Bright')

# generate choropleth map using the total immigration of each country to Canada from 1980 to 2013
folium.Choropleth(
    geo_data=world_geo,
    data=df_can,
    columns=['Country', 'Total'],
    key_on='feature.properties.name',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Immigration to Canada'
).add_to(world_map)

# display map

    world_map

I hope this helps

Related