1
votes

I'm trying to show happiness levels based on the country using folium choropleth, however, it doesn't work and all countries are just grey. This is what I get:

image output

json file: https://github.com/python-visualization/folium/blob/master/examples/data/world-countries.json

csv file: https://drive.google.com/file/d/1aI5tILdPYyx0yjbgPPZcJHEqxbZ4oPBg/view?usp=sharing

and this is my code:

import folium
import pandas as pd


country_geo = 'world-countries.json'

country_data = pd.read_csv('Happiness_Dataset_2016.csv')

bins = list(country_data['Happiness Score'].quantile([0, 0.25, 0.5, 0.75, 1]))

m = folium.Map(location=[0,0], zoom_start=2)


folium.Choropleth(
    geo_data=country_geo,
    name='choropleth',
    data=country_data,
    columns=['Country','Happiness Score'],
    Key_on='feature.properties.name',
    fill_color='BuPu',
    fill_opacity=0.2,
    line_opacity=0.5,

    legend_name='Happiness Rates (%)',
    bins =bins,

    reset=True
).add_to(m)
# folium.LayerControl().add_to(m)
m
m.save('worldmap.html')
1
Hello Quint and welcome! Can you please edit your post to include code fences, and also name your links so they are easier to understand?Nik P
Please, provide full code and data. Thanks.sentence
I just uploaded the csv and json file links. and that is all the code that I got, i just need to produce an image.quint qas

1 Answers

0
votes

Here the error:

Key_on='feature.properties.name',

Modify it as:

key_on='feature.properties.name',

and you get:

enter image description here