蓇葖果只显示灰色的颜色

问题描述 投票:0回答:1

我试图使用folium choropleth来显示基于国家的幸福感水平,然而,它不起作用,所有国家都是灰色的。这是我得到的结果。

image output

json文件: https:/github.python-visualizationfoliumblobmasterexamplesdataworld-countries.json。

csv文件。https:/drive.google.comfiled1aI5tILdPYyx0yjbgPPZcJHEqxbZ4oPBgview?usp=共享。

这是我的代码。

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')
folium choropleth
1个回答
0
投票

这里是错误。

Key_on='feature.properties.name',

修改为:

key_on='feature.properties.name',

然后你就得到:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.