[英]How to crosstab distance in pandas
Here's my Input这是我的输入
City Logitude Latitude
A 2 2
B 5 6
C 8 10
Here's my Output, calculation using Pythagoras formula这是我的 Output,使用毕达哥拉斯公式计算
A B C
A 0 5 10
B 5 0 5
C 10 5 0
I'm only using Euclidian distance, write formula directly in formula still fine我只用欧几里德距离,直接在公式里写公式还是可以的
Create a matrix of longitude and latitude only, then you can use eucalidean_distance
function from the scikit-learn
library.仅创建经度和纬度矩阵,然后您可以使用
eucalidean_distance
库中的scikit-learn
。 You can later convert the result to data frame, add indices, etc.您稍后可以将结果转换为数据框、添加索引等。
from sklearn.metrics.pairwise import euclidean_distances
X = data.set_index("City")
euclidean_distances(X)
array([[ 0., 5., 10.],
[ 5., 0., 5.],
[10., 5., 0.]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.