我有一个数据集,其中包含印度每个州的人口数据。我想为每个州都绘制一个choropleth映射,并将性别比作为值。 这是我尝试过的
import folium
import pandas as pd
world_geo = r'india_state.geojson' # geojson file
link = 'https://en.wikipedia.org/wiki/List_of_states_and_union_territories_of_India_by_population'
tables = pd.read_html(link,header=0)
df_states = tables[1]
# create a plain world map
world_map = folium.Map(location=[0, 0], zoom_start=2, tiles='Mapbox Bright')
world_map.choropleth(
geo_data=world_geo,
name='choropleth',
data=df_states[:-1],
columns=['State or union territory', 'Sex ratio'],
key_on='feature.properties.name',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Unemployment Rate (%)'
)
world_map
这给我一个错误
Attribute Error
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\site-packages\folium\folium.py in <listcomp>(.0)
291 return color_range[len(
292 [u for u in color_domain if
--> 293 get_by_key(x, key_on) in color_data and
294 u <= color_data[get_by_key(x, key_on)]])]
295 else:
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\site-packages\folium\folium.py in get_by_key(obj, key)
286 return (obj.get(key, None) if len(key.split('.')) <= 1 else
287 get_by_key(obj.get(key.split('.')[0], None),
--> 288 '.'.join(key.split('.')[1:])))
289
290 def color_scale_fun(x):
c:\users\himanshu poddar\appdata\local\programs\python\python36-32\lib\site-packages\folium\folium.py in get_by_key(obj, key)
285 def get_by_key(obj, key):
286 return (obj.get(key, None) if len(key.split('.')) <= 1 else
--> 287 get_by_key(obj.get(key.split('.')[0], None),
288 '.'.join(key.split('.')[1:])))
289
AttributeError: 'NoneType' object has no attribute 'get'
您可以从此link下载并验证geojson数据。 任何帮助将不胜感激。