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

如何用Pandas和Geopy将地址解析的经纬度拆分为单独列?

地址坐标拆分与Folium适配方案

一、拆分point列为独立的latitude和longitude列

针对你point列中的元组数据(如(27.9477595, -82.458444, 0.0)),有两种简洁的方法拆分出纬度和经度:

方法1:使用apply处理空值与提取元素

这种方法可以明确处理point列为None的情况:

# 提取纬度(元组第一个元素)
df_trainers['latitude'] = df_trainers['point'].apply(lambda x: x[0] if x is not None else None)
# 提取经度(元组第二个元素)
df_trainers['longitude'] = df_trainers['point'].apply(lambda x: x[1] if x is not None else None)

方法2:使用pandas的字符串索引(更简洁)

pandas支持直接对元组列使用str索引提取元素,会自动处理空值:

df_trainers['latitude'] = df_trainers['point'].str[0]
df_trainers['longitude'] = df_trainers['point'].str[1]

二、Folium对合并坐标数据的支持

Folium支持直接使用元组格式的坐标数据,无需强制拆分。大部分标记类(如Marker、CircleMarker)的location参数接受元组/列表格式的(纬度, 经度):

示例代码:

import folium

# 创建基础地图
m = folium.Map(location=[27.9477595, -82.458444], zoom_start=12)

# 遍历数据添加标记
for _, row in df_trainers.iterrows():
    if row['point']:
        # 取元组前两个元素(忽略海拔值0.0)
        folium.Marker(
            location=row['point'][:2],
            popup=row['full_address']
        ).add_to(m)

# 保存或显示地图
m.save('trainers_map.html')

需要注意:如果元组包含海拔值(如你的数据中的第三个元素0.0),Folium不需要该值,所以取前两个元素传入即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 19:56:50