使用大叶草绘制特定国家的世界卵泡图时出错

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

我正在尝试使用python folium绘制特定国家的choropleth地图,如下所示:

#!/usr/bin/python3 
import pandas as pd
import os
import folium

country_count = pd.read_csv('countries.csv')

country_geo = os.path.join('world-countries.json')

m = folium.Map(location=[0, 0], zoom_start=2)
m.choropleth(
 geo_data=country_geo,
 name='choropleth',
 data=country_count,
 columns=['Country_0'],
 key_on='feature.properties.name',
 fill_color='YlGn',
 fill_opacity=0.7,
 line_opacity=0.2,
 legend_name='Test'
)
folium.LayerControl().add_to(m)

m.save('#292_folium_chloropleth_country.html')

其中countries.csv如下:

Country                 
United States of America 
United Kingdom              
France                      
Canada                      
Japan                       
Italy                       
Germany                     
Russia                      
India                       
Spain                       
Australia                   
Hong Kong                   
South Korea

当我尝试编译此代码时,出现此错误,如下所示:

Traceback (most recent call last):
  File "choropleth1.py", line 20, in <module>
    legend_name='Test'
  File "/home/ammar/.local/lib/python3.7/site-packages/folium/folium.py", line 418, in choropleth
    self.add_child(Choropleth(*args, **kwargs))
  File "/home/ammar/.local/lib/python3.7/site-packages/folium/features.py", line 1063, in __init__
    color_data = data.set_index(columns[0])[columns[1]].to_dict()
  File "/home/ammar/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 4396, in set_index
    raise KeyError("None of {} are in the columns".format(missing))
KeyError: "None of ['Country'] are in the columns"

我可以使用其名称或三个字母代码(例如美国的美利坚合众国)为特定国家/地区制作choropleth地图的解决方案吗?>>

我正在尝试使用python folium绘制特定国家/地区的choropleth地图,如下所示:#!/ usr / bin / python3 import pandas as pd import os import folium country_count = pd.read_csv('countries ....

python data-visualization folium
1个回答
0
投票

您的列应该是“国家”,而不是“国家_0”

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