Сначала вы можете создать внешнее объединение, используя
import pandas as pd
import numpy as np
df1 = pd.DataFrame({
'Person': ['A_first', 'A_last', 'B_first', 'B_last'],
'X': [260357.3199, 261618.5243, 258270.5926, 258270.5926],
'Y': [4064458.685, 4064789.928, 4063717.789, 4063717.789],
})
df2 = pd.DataFrame({
'BS': ['BS1', 'BS2'],
'X': [258280.8228, 259961.3734],
'Y': [4063715.835, 4064840.298],
})
df1['key'] = 0
df2['key'] = 0
df_cartesian = df1.merge(df2, on='key').drop(columns=['key'])
Затем рассчитайте построчную разницу X и Y и возьмите норму L2:
df_cartesian['X_diff'] = df_cartesian['X_x'] - df_cartesian['X_y']
df_cartesian['Y_diff'] = df_cartesian['Y_x'] - df_cartesian['Y_y']
df_cartesian['dist'] = np.linalg.norm(df_cartesian[['X_diff', 'Y_diff']], axis=1)
df_cartesian
# Person X_x Y_x BS X_y Y_y \
# 0 A_first 260357.3199 4064458.685 BS1 258280.8228 4063715.835
# 1 A_first 260357.3199 4064458.685 BS2 259961.3734 4064840.298
# 2 A_last 261618.5243 4064789.928 BS1 258280.8228 4063715.835
# 3 A_last 261618.5243 4064789.928 BS2 259961.3734 4064840.298
# 4 B_first 258270.5926 4063717.789 BS1 258280.8228 4063715.835
# 5 B_first 258270.5926 4063717.789 BS2 259961.3734 4064840.298
# 6 B_last 258270.5926 4063717.789 BS1 258280.8228 4063715.835
# 7 B_last 258270.5926 4063717.789 BS2 259961.3734 4064840.298
#
# X_diff Y_diff dist
# 0 2076.4971 742.850 2205.372152
# 1 395.9465 -381.613 549.911004
# 2 3337.7015 1074.093 3506.269681
# 3 1657.1509 -50.370 1657.916235
# 4 -10.2302 1.954 10.415138
# 5 -1690.7808 -1122.509 2029.474358
# 6 -10.2302 1.954 10.415138
# 7 -1690.7808 -1122.509 2029.474358