Folium地图没有属性geo_json

时间:2018-11-03 21:12:04

标签: python leaflet folium

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

在map1.geo_json(...)上出现以下错误:

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

我已经检查过我是否具有最新版本的大叶草。如何使用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)

1 个答案:

答案 0 :(得分:1)

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

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