Folium 地图没有属性 geo_json

Folium map has no attribute geo_json

我正在尝试实现 this tutorial 中的第二个脚本。我的代码与教程中的代码几乎相同并粘贴在下面。

我在 map1.geo_json(...) 上收到以下错误:

AttributeError: 'Map' object has no attribute 'geo_json'

我已经确认我有最新版本的 folium。如何使用此 geo_json 功能?

import folium

SF_COORDINATES = (37.76, -122.45)
#crimedata = pd.read_csv('SFPD_Incidents_-_Current_Year__2015_.csv')

# definition of the boundaries in the map
district_geo = '/Users/alexiseggermont/Dropbox/01. Personal/04. Models/23. Immoweb/BEL_adm_shp/BEL_adm4.geojson'

# calculating total naumber of incidents per district
merged2 = data_for_map.set_index('NAME_4')#pd.DataFrame(merged['PdDistrict'].value_counts().astype(float))
merged2.to_json('/Users/alexiseggermont/Dropbox/01. Personal/04. Models/23. Immoweb/BEL_adm_shp/merged2.json')
merged2 = merged2.reset_index()
merged2.columns = ['NAME_4', 'prix_par_mc']

# creation of the choropleth
map1 = folium.Map(location=SF_COORDINATES, zoom_start=12)
map1.geo_json(geo_path = district_geo, 
              data_out = '/Users/alexiseggermont/Dropbox/01. Personal/04. Models/23. Immoweb/BEL_adm_shp/merged2.json', 
              data = merged2,
              columns = ['NAME_4', 'prix_par_mc'],
              key_on = 'feature.properties.NAME_4',
              fill_color = 'YlOrRd', 
              fill_opacity = 0.7, 
              line_opacity = 0.2,
              legend_name = 'price per square meter')

display(map1)

如果您收到 AttributeError,我总是建议阅读文档以防方法已被移动。

在您的情况下,您正在寻找 folium.GeoJson