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

pandas经纬度列生成元组用于googlemaps反向地理编码报错处理

错误原因

报错触发的根本原因是Python内置tuple()函数仅支持接收1个可迭代对象作为入参,你的代码中给tuple()同时传入了row.Latitude、row.Longitude两个独立浮点参数,不符合函数调用规则。

解决方法

将循环内调用reverse_geocode的代码行修改为以下任意一种写法即可:

  • 直接构造元组(写法更简洁,无需额外调用tuple()函数):
response = gmaps.reverse_geocode((row.Latitude, row.Longitude))
  • 如果你要保留tuple()的调用,需要把两个坐标值打包到同一个可迭代对象(比如列表)中再传入:
response = gmaps.reverse_geocode(tuple([row.Latitude, row.Longitude]))

可选优化

你也可以直接用pandas的apply方法替代手写循环,代码更简洁高效:

test['response'] = test.apply(lambda row: gmaps.reverse_geocode((row.Latitude, row.Longitude)), axis=1)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 03:54:03