folium Choropleth 颜色仅显示灰色
folium Choropleth colors showing grey only
我正在尝试使用 folium choropleth 显示基于国家/地区的幸福水平,但是,它不起作用,所有国家/地区都是灰色的。这就是我得到的:
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')
此处错误:
Key_on='feature.properties.name',
修改为:
key_on='feature.properties.name',
你得到:
我正在尝试使用 folium choropleth 显示基于国家/地区的幸福水平,但是,它不起作用,所有国家/地区都是灰色的。这就是我得到的:
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')
此处错误:
Key_on='feature.properties.name',
修改为:
key_on='feature.properties.name',
你得到: