保存时Folium映射KeyError ATA

时间:2017-11-02 21:20:01

标签: python pandas visualization data-science folium

尝试保存地图时出现以下错误

'KeyError                                  Traceback (most recent call last)
<ipython-input-31-65c9bba51b6f> in <module>()
  7 # Create Folium plot
  8 #map.save('plot_data.html')
----> 9 map.save(outfile= "test.html")
KeyError: 'ATA'

这是我的代码,在这里我试图绑定pandas数据框和json几何图形来创建用于数据可视化的叠加

import folium
import pandas as pd
country_geo  = './world-development-indicators/world-countries.json'
data = pd.read_csv('world-development-indicators/Indicators.csv')
hist_indicator = 'CO2 emissions \(metric'
hist_year = 2011
mask1 = data['IndicatorName'].str.contains(hist_indicator) 
mask2 = data['Year'].isin([hist_year])
stage = data[mask1 & mask2]
plot_data = stage[['CountryCode','Value']]
hist_indicator = stage.iloc[0]['IndicatorName']
map = folium.Map(location=[100, 0], zoom_start=1)
map.choropleth(geo_path=country_geo, data=plot_data,
         columns=['CountryCode', 'Value'],
         key_on='feature.id',
         fill_color='YlGnBu', fill_opacity=0.7, line_opacity=0.2,
         legend_name=hist_indicator)
map.save('plot_data.html')

0 个答案:

没有答案