Я получаю AttributeError: объект 'NoneType' не имеет атрибута 'get' , когда я пытался создать карту Choropleth. Что пошло не так?
Ошибка
AttributeError Traceback (most recent call last)
<ipython-input-21-15d9491e7d8a> in <module>()
25 fill_opacity=0.7,
26 line_opacity=0.2,
---> 27 legend_name='Lorem Ipsum'
28 ).add_to(Toronto_map)
29 # display map
6 frames
/usr/local/lib/python3.6/dist-packages/folium/features.py in get_by_key(obj, key)
993 def get_by_key(obj, key):
994 return (obj.get(key, None) if len(key.split('.')) <= 1 else
--> 995 get_by_key(obj.get(key.split('.')[0], None),
996 '.'.join(key.split('.')[1:])))
997
AttributeError: 'NoneType' object has no attribute 'get'
Моя попытка карты Choropleth
threshold_scale = np.linspace(df['Percent'].min(),
df['Percent'].max(),
12, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration
# download countries geojson file
!wget --quiet https://...some path../world_countries.json
world_geo = r'world_countries.json' # geojson file
# create map and display it
Toronto_map = folium.Map(location=[43.653963, -79.387207], zoom_start=12)
# generate choropleth map
folium.Choropleth(
geo_data=world_geo,
data=dfC,
columns=['location', 'Percent'],
key_on='Feature.properties.name',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Lorem Ipsum'
).add_to(Toronto_map)
# display map
Toronto_map
Мойданные dfC
структура , всего 12 строк
location Ethnic Percent lat lng
0 Beaches-East York Canadian , English , Scottish 21.0 43.681470 -79.306021
Скопируйте и вставьте сюда часть файла геоджон
{"type":"Feature","properties":{"name":"Canada"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-63.6645,46.55001],[-62.9393,46.41587],[-62.01208,46.44314],[-62.50391,46.03339],[-62.87433,45.96818],[-64.1428,46.39265],[-64.39261,46.72747],[-64.01486,47.03601],[-63.6645,46.55001]]],[[[-61.806305,49.10506],[-62.29318,49.08717],[-63.58926,49.40069],[-64.51912,49.87304],[-64.17322,49.95718].....[-70.665765,83.169781],[-68.5,83.106322]]]]},"id":"CAN"},