问题描述
我想使用两列计算坐标之间的距离。一种用于纬度,一种用于经度。我使用haversine公式成功地获得了距离。但是,我读到这种方法更准确,因为它假设地球是椭球体而不是球体。
但是,对于这种方法,似乎不能使用列。如何克服这种情况?
@H_404_5@# Random values for the duration from one point to another random_values = random.sample(range(2,20),8) random_values # Creating arrays for the coordinates lat_coor = [11.923855,11.923862,11.923851,11.923847,11.923865,11.923841,11.923860,11.923846] lon_coor = [57.723843,57.723831,57.723839,57.723827,57.723835,57.723827] df = pd.DataFrame( {'duration': random_values,'latitude': lat_coor,'longitude': lon_coor }) df duration latitude longitude 0 5 11.923855 57.723843 1 2 11.923862 57.723831 2 10 11.923851 57.723839 3 19 11.923847 57.723831 4 16 11.923865 57.723827 5 4 11.923841 57.723831 6 13 11.923860 57.723835 7 3 11.923846 57.723827 df2 = pd.concat([df.add_suffix('_pre').shift(),df],axis=1) df2[["latitude_pre","longitude_pre"]] latitude_pre longitude_pre 0 NaN NaN 1 11.923855 57.723843 2 11.923862 57.723831 3 11.923851 57.723839 4 11.923847 57.723831 5 11.923865 57.723827 6 11.923841 57.723831 7 11.923860 57.723835 df2.apply(geopy.distance.distance(df2['latitude_pre'],df2['longitude_pre']),axis=1) ValueError: When creating a Point from sequence,it must not have more than 3 items.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)