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

folium绘制Circle无效果,传入DataFrame坐标参数无法正常显示

问题原因与修复方案

核心问题

  • 遍历pandas DataFrame的逻辑错误:直接执行for coordinate in koala_df时,遍历对象是DataFrame的列名,而非每一行的观测数据,拿到的coordinate完全不包含坐标值
  • 坐标传参语法错误:coordinate[["decimalLatitude"],coordinate["decimalLongitude"]]是非法的取值写法,folium的Circle的location参数仅需要传入[纬度值, 经度值]格式的一维列表即可
  • 额外问题:你使用了空的try...except结构吞掉了所有错误提示,导致无法直接看到报错原因,调试阶段建议先去掉异常捕获逻辑,方便定位问题

修复后代码

import folium

map_of_koala_sightings = folium.Map(
    location =[-27.470125,153.021072],
    zoom_start=13, 
    tiles='Stamen Terrain'
)

# 用iterrows遍历DataFrame的每一行
for idx, row in koala_df.iterrows():
    folium.Circle(
        radius=300,
        # 正确取两个字段的值拼成坐标列表
        location = [row["decimalLatitude"], row["decimalLongitude"]],
        color='#3388ff',
        fill=True
    ).add_to(map_of_koala_sightings)

map_of_koala_sightings

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 08:57:02