Problem resolving: ValueError: Cannot render objects with any missing geometries: type features

Problem resolving: ValueError: Cannot render objects with any missing geometries: type features

我正在尝试使用 folium 创建等值线图。但是我下面的代码一直在说:

  ValueError: Cannot render objects with any missing geometries: type features

使用的代码是:

 url='https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/Canada.xlsx'

 df_can=pd.read_excel(url, sheet_name='Canada by Citizenship', skiprows=range(20), skipfooter=2)

   df_can.drop(['AREA','REG','DEV','Type','Coverage'], axis=1, inplace=True)

df_can.rename(columns={'OdName':'Country', 'AreaName':'Continent','RegName':'Region'}, inplace=True)

df_can.columns=list(map(str, df_can.columns))

df_can['Total']=df_can.sum(axis=1)

years=list(map(str, range(1980,2014)))

   JSON='https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/world_countries.json'

 world_geo=pd.read_json(JSON)

   world_map=folium.Map(location=[0,0], zoom_start=2)

   world_map.choropleth(
    geo_data=world_geo,
    data=df_can,
    columns=['Country', 'Total'],
    key_on='feature.properties.name',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Immigration to Canada'
  )

# display map
world_map

请帮我看看哪里出了问题?

我认为错误的原因是geojson加载的是数据框。通常,您会将 geojson 文件与要可视化的数据框相关联。该关联的格式需要为字典格式。

import json
from urllib.request import urlopen

JSON='https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/world_countries.json'

with urlopen(JSON) as f:
    world_geo = json.load(f)
# world_geo=pd.read_json(JSON)

world_map = folium.Map(location=[0,0], zoom_start=2)

folium.Choropleth(
    geo_data=world_geo,
    data=df_can,
    columns=['Country', 'Total'],
    key_on='feature.properties.name',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Immigration to Canada'
  ).add_to(world_map)

# display map
world_map