如何计算pandas数据帧之间的haversine交叉距离

How how to calculate haversine cross-distance between to pandas dataframe

这是我的数据集B

   index       lon        lat
0   0   107.071969  -6.347778
1   1   110.431361  -7.773489
2   2   111.978469  -8.065442

和数据集C

    index      lon        lat
5   5   112.340919  -7.520442
6   6   107.179119  -6.291131
7   7   106.807442  -6.437383

我需要的输出是(计算完全随机)

           0       1        2 
  5      4.5     7.7      7.8 
  6      5.9     7.9      2.8
  7      6.7     7.7     10.2

我的尝试

from haversine import haversine
haversine(B,C)

输出

ValueError                                Traceback (most recent call last)
<ipython-input-55-3078154d1efc> in <module>
      1 from haversine import haversine
----> 2 haversine(B,C)

~/.local/lib/python3.6/site-packages/haversine/haversine.py in haversine(point1, point2, unit)
     86 
     87     # unpack latitude/longitude
---> 88     lat1, lng1 = point1
     89     lat2, lng2 = point2
     90 

ValueError: too many values to unpack (expected 2)

检查你的输出距离,它们是什么单位?我把我的转换成公里。如果需要,您可以使用在线距离计算器进行检查。让我知道

import numpy as np
import pandas as pd
from sklearn.metrics.pairwise import haversine_distances
pd.DataFrame(haversine_distances(np.radians(df1[['lat','lon']]),np.radians(df2[['lat','lon']]))* 6371,index=df1.index, columns=df2.index)



    5           6           7
0  596.019968   13.413123   30.882602
1  212.317223  394.942014  426.564799
2   72.573637  565.020998  598.409848