【发布时间】:2022-06-10 17:43:46
【问题描述】:
我有两个具有经度和纬度列的数据框。 DF1 和 DF2:
DF1 = pd.DataFrame([[19.827658,-20.372238,8614], [19.825407,-20.362608,7412], [19.081514,-17.134456,8121]], columns=['Longitude1', 'Latitude1','Echo_top_height'])
DF2 = pd.DataFrame([[19.083727, -17.151207, 285.319994], [19.169403, -17.154144, 284.349994], [19.081514,-17.154456, 285.349994]], columns=['Longitude2', 'Latitude2','BT'])
我需要在 DF1 中找到 long 和 lat 与 DF2 中的 long 和 lat 的匹配项。并且在数据匹配的地方,从DF2到DF1的BT列中添加相应的值。
我使用来自here 的代码并设法检查是否有匹配项:
from sklearn.metrics.pairwise import haversine_distances
threshold = 5000 # meters
earth_radius = 6371000 # meters
DF1['nearby'] = (
# get the distance between all points of each DF
haversine_distances(
# note that you need to convert to radiant with *np.pi/180
X=DF1[['Latitude1','Longitude1']].to_numpy()*np.pi/180,
Y=DF2[['Latitude2','Longitude2']].to_numpy()*np.pi/180)
*earth_radius < threshold).any(axis=1).astype(int)
所以我需要的结果是这样的:
Longitude1 Latitude1 Echo_top_height BT
19.82 -20.37 8614 290.345
19.82 -20.36 7412 289.235
and so on...
【问题讨论】:
-
请以文本而非图像的形式发布示例输入数据:stackoverflow.com/questions/20109391/…