叶片叶绿藻的颜色仅显示灰色

时间:2020-05-15 10:41:18

标签: python python-3.x pandas folium choropleth

我正在尝试使用大叶cho叶来显示该国家/地区的幸福水平,但是,它不起作用,并且所有国家/地区都只有灰色。这就是我得到的:

image output

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

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

这是我的代码:

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 个答案:

答案 0 :(得分:0)

这里是错误:

Key_on='feature.properties.name',

修改为:

key_on='feature.properties.name',

您会得到:

enter image description here