在熊猫/python中的相对距离
我有一个带有一系列位置的数据框。到目前为止,我拥有的三列是:
['Location number','x_coordinate', 'y_coordinate]
现在我想拥有一个指示距离的第四列。在上一个。
由于FIRTS位置没有前面的位置,因此我的距离不能为零。
对于另一个位置,“曼哈顿距离”应该最容易计算,并且非常适合我使用。
对于那些不熟悉的曼哈顿距离的人:delta x + delta y
I have a dataframe with a series of locations in it. The three columns i have so far are:
['Location number','x_coordinate', 'y_coordinate]
Now i would like to have a forth column which indicates the distance. between te previous one.
As the firts location does not has a preceding location, i't distance can just be zero.
For the other location, 'manhattan distance' should be most easy to compute, and is just perfect for my use.
For those not familiar to the manhattan distance: delta x + delta y
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
/a>方法应该解决:
The
pd.Series.diff
method should do the trick:刚刚找到了可能工作得更好的解决方案:
来源:
https://docs.scipy.org/doc/doc/scipy/reference/reference/generated/generated/generated/scipy.spatial.distance.cdist.cdist.html #html#scipipy.spatial.distististial.distist. CDIST
Just found a solution that might work better:
Source:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html#scipy.spatial.distance.cdist