My data frame has 16 x and y coordinates for positions{x1,x2...x16,y1,y2...y16} continuous from 0 to 566(m). I want to calculate Euclidean distance between x1,y1 wrt the remaining 15 coordinates and get the overall average distance. I want to repeat the process for all the 16 coordinates in the data frame and get their average distances from the other points.
My Data frame
import pandas as pd
import plotly.express as px
sample = {'index': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'columns': ['X1',
'X2',
'X3',
'X4',
'X5',
'X6',
'X7',
'X8',
'X9',
'X10',
'X11',
'X12',
'X13',
'X14',
'X15',
'X16',
'Y1',
'Y2',
'Y3',
'Y4',
'Y5',
'Y6',
'Y7',
'Y8',
'Y9',
'Y10',
'Y11',
'Y12',
'Y13',
'Y14',
'Y15',
'Y16'],
'data': [[500.4677, 278.6497, 47.4062, 417.3653, 551.7083, 401.1797, 0.0, 161.7773, 368.1543, 45.985, 520.4714, 566.0, 219.715, 45.0157, 284.9714, 202.886, 26.0476, 566.0, 0.0, 104.1045, 0.0, 335.7074, 486.5247, 566.0, 566.0, 258.2014, 376.2201, 477.4717, 412.28, 96.7684, 90.1294, 364.7503],
[511.751, 104.4383, 566.0, 380.4079, 345.8587, 0.0, 90.5588, 7.2899, 566.0, 566.0, 566.0, 313.0356, 191.8169, 200.6335, 566.0, 383.5991, 566.0, 135.7882, 463.57800000000003, 366.7474, 447.0349, 0.0, 410.16, 246.4883, 0.0, 208.0817, 60.8637, 566.0, 48.4488, 117.445, 411.2962, 566.0],
[19.699, 216.4378, 355.296, 67.8151, 518.7256, 72.1572, 222.7933, 223.9242, 566.0, 312.4474, 511.7909, 566.0, 78.0924, 226.1336, 566.0, 465.5424, 0.0, 566.0, 447.2046, 259.9073, 566.0, 320.6664, 418.3566, 351.0215, 354.9378, 566.0, 391.7332, 99.2301, 0.0, 137.3001, 535.2882, 566.0],
[0.0, 0.0, 243.342, 0.0, 566.0, 0.0, 198.4878, 0.0, 566.0, 566.0, 509.8984, 285.704, 144.3917, 294.7953, 399.9559, 345.9918, 380.3994, 462.8946, 566.0, 566.0, 0.0, 0.0, 234.3866, 53.6411, 546.4076, 253.0758, 0.0, 53.9287, 396.4652, 0.0, 0.0, 10.9969],
[446.6611, 421.0366, 493.1895, 566.0, 516.3773, 566.0, 566.0, 474.81699999999995, 566.0, 0.0, 299.7096, 30.5458, 0.0, 170.8087, 178.8432, 187.1938, 278.2215, 0.0, 551.9664, 566.0, 373.9421, 313.9131, 485.6295, 433.9819, 0.0, 481.3123, 0.0, 566.0, 0.0, 6.0358, 566.0, 465.4973],
[398.0662, 0.0, 172.95, 480.6902, 566.0, 566.0, 257.4459, 67.4326, 5.4764, 566.0, 0.0, 62.1571, 143.9684, 566.0, 236.2575, 341.5666, 102.6265, 484.4441, 7.9433, 0.0, 320.2722, 26.7175, 566.0, 540.0883, 349.5919, 213.1047, 0.0, 0.0, 566.0, 566.0, 503.7899, 116.725],
[113.7286, 341.2415, 418.0059, 0.0, 566.0, 566.0, 566.0, 0.0, 0.0, 566.0, 68.0914, 463.0868, 140.684, 18.4887, 220.1713, 273.2086, 566.0, 0.0, 270.9991, 503.3479, 0.0, 89.0062, 509.5509, 566.0, 287.7841, 566.0, 334.3373, 54.4844, 0.0, 206.8418, 396.798, 566.0],
[0.0, 0.0, 0.0, 557.9507, 0.0, 566.0, 530.5327, 566.0, 461.61400000000003, 495.1422, 243.7463, 515.1805, 337.0039, 149.3637, 432.7603, 375.4085, 216.9741, 566.0, 424.6422, 405.3143, 323.5063, 160.0276, 0.0, 566.0, 566.0, 420.6266, 566.0, 566.0, 58.6311, 255.0382, 0.0, 566.0],
[369.2071, 304.0515, 566.0, 164.3125, 552.6091, 557.8421, 437.3143, 395.9587, 417.7882, 0.0, 0.0, 198.0035, 121.6725, 169.035, 225.88400000000001, 12.7346, 0.0, 476.0819, 0.0, 503.4461, 566.0, 447.1827, 53.9382, 566.0, 484.8547, 0.0, 566.0, 566.0, 566.0, 0.0, 362.2357, 269.9263],
[39.8478, 231.8411, 176.4778, 0.0, 566.0, 0.0, 566.0, 202.1302, 566.0, 291.1011, 0.0, 511.6552, 566.0, 113.6815, 566.0, 0.0, 512.7862, 177.8265, 85.63799999999999, 566.0, 0.0, 6.2889, 305.5369, 0.0, 566.0, 529.326, 136.871, 502.9318, 117.4366, 130.5829, 168.2698, 376.7318]]}
df = pd.DataFrame(index=sample['index'], columns=sample['columns'],
data=sample['data'])
df
I have tried with below math formulae for all the coordinated individually and added all the distanced for the coordinate 1 to get the average distance for coordinate 1.
x1 = df.X1
x1 = df.X2
y1 = df.Y1
y2 = df.Y2
d12 = np.sqrt(np.square( x2 - x1 ) + np.square( y2 - y1 ))
avgd1 = (d12+d13+d14+d15+d16+d17+d18+d19+d110+d111+d112+d113+d114+d115+d116)/16.00
Similarly, I have taken average distances for all the 16 coordinates. But its not an efficient way and the code is getting very lengthy. Also my data set is very huge. So i want to know if there are any other efficient methods for my problem.