Folium错误“Map”对象没有属性“geo\u json”

2024-04-25 18:51:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用GeoJson时遇到AttributeError。我看了医生,但找不到任何线索来解释原因。在

import folium
from folium import GeoJson 


LA_COORDINATES = (34.0522, -118.2437)
zip_geo = r'zip-code-tabulation-areas-2012.geojson'

df_zip.to_json('ticket_agg.json')
df_zip.columns = ['Zipcode','Ticket_Count']

# creation of the choropleth
map1 = folium.Map(location=LA_COORDINATES, zoom_start=12)
map1.GeoJson(geo_path = zip_geo, 
              data_out = 'ticket_agg.json', 
              data = df_zip,
              columns = ['Zipcode','Ticket_Count'],
              key_on = 'feature.properties.external_id',
              fill_color = 'YlOrRd', 
              fill_opacity = 0.7, 
              line_opacity = 0.2,
              legend_name = 'Tickets per zip')

display(map1)

错误:

^{pr2}$

这是指向我正在使用的geo\u json文件的链接:http://s3-us-west-2.amazonaws.com/boundaries.latimes.com/archive/1.0/boundary-set/zip-code-tabulation-areas-2012.geojson

任何建议都将不胜感激!在


Tags: importjsondfgeojsoncodezipticketla
1条回答
网友
1楼 · 发布于 2024-04-25 18:51:37

显然是错误

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

由于GeoJson不是Map类的方法而发生。在

{em}我想建议最新版本的

folium.Choropleth(
    geo_path = zip_geo, 
    data = df_zip,
    columns = ['Zipcode','Ticket_Count'],
    key_on = 'feature.properties.external_id',
    fill_color = 'YlOrRd', 
    fill_opacity = 0.7, 
    line_opacity = 0.2,
    legend_name = 'Tickets per zip'
).add_to(map1)

列出变更

相关问题 更多 >