如何在python-error中找到在给定经度和纬度的两点之间的距离? [英] How to find the distance between two points given longitude and latitude in python-error?

查看:93
本文介绍了如何在python-error中找到在给定经度和纬度的两点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个经度和纬度的位置,我想在python中获得这些点之间的距离.我的数据集如下所示:

I have two locations with longitude and latitude given and I would like to get the distance between these points in python. My data set looks like below:

df_TEST = pd.DataFrame({'Location': ['X'],
                     'Long': [ 28.63615701706],
                     'Lat': [ 41.0693487044612],
                     'Location1': ['Y'],
                     'Long1': [30.7158891385255],
                     'Lat1': [36.963486025471]})  

我建议的解决方案基于纬度/经度

 df_TEST['distance']=geopy.distance.geodesic(( df_TEST['Long'], 
 df_TEST['Lat']),(df_TEST['Long1'], df_TEST['Lat1'])).km

以下我的错误,请让我知道如何解决.谢谢.

My error below please let me know how to fix this. Thank you.

ValueError: The truth value of a Series is ambiguous. Use a.empty, 
a.bool(), a.item(), a.any() or a.all().

推荐答案

As seen in the Documentation it accepts float tuple and not a pandas series tuple that you are trying to do here, try this instead:

df_TEST['distance']=geopy.distance.geodesic(( float(df_TEST['Long']), 
 float(df_TEST['Lat'])),(float(df_TEST['Long1']), float(df_TEST['Lat1']))).km

这篇关于如何在python-error中找到在给定经度和纬度的两点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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