python - 文森蒂距离系列
问题描述
我有带有纬度和经度列的熊猫数据框,并且想要计算两个连续点之间的 vincenty 距离pi
和pi+1
.
lat long
1 39.9852833333333 116.307367
2 39.9852166666667 116.309550
3 39.9851333333333 116.309767
4 39.9850666666667 116.309883
5 39.9847333333333 116.309933
df['distance'] = vincenty( (df['lat'],df['long']), (df['lat'].shift(-1), df['long'].shift(-1)) )
我收到以下错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
解决方案
我认为需要先创建新列,然后dropna
用于删除 and 中的最后sNaN
行lat_shifted
,long_shifted
所以最后一个值为Vincenty_distance
:NaN
df['lat_shifted'] = df['lat'].shift(-1)
df['long_shifted'] = df['long'].shift(-1)
df['Vincenty_distance'] = df.dropna().apply(lambda x: vincenty((x['lat'], x['long']), (x['lat_shifted'], x['long_shifted'])), axis = 1)
推荐阅读
- python - python中的类对象列表
- r - 试图在 r 中计算每月、每年的死亡人数
- ruby-on-rails - 如何计算文件文档 ruby gem 中的页数?
- tensorflow - 用于对象检测的精灵图像
- javascript - 无法读取播放错误的属性,不确定这意味着什么
- clojure - 试剂原子交换!将状态更改为键中的所有值
- python - 使用 Python Webhooks 将带有预览的嵌入式链接发布到 Discord
- node.js - 忽略 AdonisJs 中唯一验证规则中的多个字段
- express - 在 Heroku 上部署时的 Axios 代理
- python - I want to make a sorting Visualizer, the sort works but visualizer doesnot