大 pandas 数据框中点坐标的欧几里得距离 [英] Euclidean distance of points coordinates in pandas dataframe

查看:55
本文介绍了大 pandas 数据框中点坐标的欧几里得距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个六列的pandas数据框,前三列包含 x y z 参考坐标,接下来的三列是-某个点的坐标.我想将这两点之间的欧几里得距离放在数据框的新列中.我考虑过通过pandas.apply方法使用numpy.linalg.norm,但是我不知道为numpy函数解析数据帧行的最佳方法是什么.你能给我一些建议吗?

I have a pandas dataframe with six columns, first three columns contain x, y and z reference coordinate, and the next three - coordinates of some point. I want to put euclidean distance between those two points in new column of the dataframe. I think about using numpy.linalg.norm via pandas.apply method, but I don't know what is the best method to parse dataframe row for numpy function. Could you give me some suggestions?

推荐答案

在这里您可能不需要任何奇特的魔术:

You might not need any fancy magic here:

df['dist'] = np.sqrt( (df.x1-df.x2)**2 + (df.y1-df.y2)**2 + (df.z1-df.z2)**2)

这篇关于大 pandas 数据框中点坐标的欧几里得距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆