You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python Folium读取CSV绘制地图出现语法错误求助排查

代码错误点汇总
  • 提取列错误:df_locations = df_bedarf[["Latitude", "Longitude"]] 仅筛选了经纬度两列,后续代码尝试从df_locations中获取suburb/Sort/t/a字段时会抛出KeyError,需要把用到的字段都加入筛选列表。
  • 列名大小写不匹配:CSV表头字段为首字母大写的Suburb,代码中写的是小写suburb,字段名不对应会报错。
  • 方法名拼写错误:Folium绘制圆形标记的方法是大写开头的Circle,小写circle不存在,调用会抛出属性错误。
  • 语法错误1:radius = str(df_locations["t/a"][point]*100) 行末尾缺少逗号,会触发语法解析错误。
  • 语法错误2:fill_color="#17cbef 字符串缺少右侧闭合双引号,会触发语法解析错误。
  • 参数类型错误:radius参数要求传入数值类型,代码中将其转为字符串会导致渲染失败,需要删除str()转换。
修正后完整代码
import folium 
import pandas as pd

df_bedarf = pd.read_csv('C:/Users/xxxxx/Desktop/xxxxxx/xxxxxxx.csv', sep = ";")
df_bedarf.head()

# 筛选所有需要用到的字段
df_locations = df_bedarf[["Latitude", "Longitude", "Suburb", "Sort", "t/a"]]
location_list = df_locations[["Latitude", "Longitude"]].values.tolist()
location_list_size = len(location_list)

map_points = folium.Map(location = [47.57087, 13.43828], zoom_start = 7)

for point in range(0, location_list_size):
    folium.Circle(
        location = location_list[point],
        popup = df_locations["Suburb"][point] + ": " + df_locations["Sort"][point],
        radius = df_locations["t/a"][point] * 100,
        color = "#17cbef",
        fill = True,
        opacity = 0.8,
        fill_color = "#17cbef",
        stroke = True, 
        weight = 1.0,
    ).add_to(map_points)
    
map_points

内容的提问来源于stack exchange,提问作者wischi11

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 22:00:03