This Python 3 class is a solution to the StackOverflow question How to make calculations between rows with the same ID in a dataframe and add to new columns, using python asked on August 6, 2020. It does not import any third party libraries.
The Python 3 class reads an input TXT file, calculates cell distances, and saves output to a CSV file:
$ cat data.txt
SC NETWORK_ID Lat Lon
0 ED0002 41.6742 26.553130600000003
0 ED0016 41.7750556 26.9170278
0 IS0030 41.05455556 28.80925
0 IS0134 40.97616944 28.80165
1 ED0016 41.7750556 26.9170278
1 IS0096 40.99406111 28.82413056
1 IS0137 40.98033889 28.73052778
1 IS0280 41.1085556 28.874861100000004
2 ED0002 41.6742 26.553130600000003
2 ED0018 41.26675 26.687669399999997
2 IS0034 41.10741944 28.80134167
2 IS0063 40.97868889 28.72448889
2 IS0280 41.1085556 28.874861100000004
2 IS0880 41.03519444 28.82001389
3 ED0018 41.26675 26.687669399999997
3 IB9048 40.98021667 28.833175
3 IS0034 41.10741944 28.80134167
3 IS0063 40.97868889 28.72448889
3 IS0280 41.1085556 28.874861100000004
## the JSON output is manually wrapped to better fit in this listing
$ python3 distance.py
[{'SC': 0, 'NETWORK_ID': 'ED0002', 'LAT': 41.6742, 'LON': 26.553130600000003, 'NEIGH1': 0.0,
'NEIGH2': 32.21502886502109, 'NEIGH3': 200.48599610361597, 'NEIGH4': 203.16353066879788,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 0, 'NETWORK_ID': 'ED0016', 'LAT': 41.7750556, 'LON': 26.9170278,
'NEIGH1': 32.21502886502109, 'NEIGH2': 0.0, 'NEIGH3': 176.95946212304386, 'NEIGH4': 180.60233416877116,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 0, 'NETWORK_ID': 'IS0030', 'LAT': 41.05455556, 'LON': 28.80925,
'NEIGH1': 200.48599610361597, 'NEIGH2': 176.95946212304386, 'NEIGH3': 0.0, 'NEIGH4': 8.739431576792299,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 0, 'NETWORK_ID': 'IS0134', 'LAT': 40.97616944, 'LON': 28.80165,
'NEIGH1': 203.16353066879788, 'NEIGH2': 180.60233416877116, 'NEIGH3': 8.739431576792299, 'NEIGH4': 0.0,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 1, 'NETWORK_ID': 'ED0016', 'LAT': 41.7750556, 'LON': 26.9170278,
'NEIGH1': 0.0, 'NEIGH2': 181.25721917309428, 'NEIGH3': 175.22169273308518, 'NEIGH4': 179.22877097784087,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 1, 'NETWORK_ID': 'IS0096', 'LAT': 40.99406111, 'LON': 28.82413056,
'NEIGH1': 181.25721917309428, 'NEIGH2': 0.0, 'NEIGH3': 8.003453963767388, 'NEIGH4': 13.423113789153426,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 1, 'NETWORK_ID': 'IS0137', 'LAT': 40.98033889, 'LON': 28.73052778,
'NEIGH1': 175.22169273308518, 'NEIGH2': 8.003453963767388, 'NEIGH3': 0.0, 'NEIGH4': 18.70230868984524,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 1, 'NETWORK_ID': 'IS0280', 'LAT': 41.1085556, 'LON': 28.874861100000004,
'NEIGH1': 179.22877097784087, 'NEIGH2': 13.423113789153426, 'NEIGH3': 18.70230868984524, 'NEIGH4': 0.0,
'NEIGH5': '', 'NEIGH6': ''}, {'SC': 2, 'NETWORK_ID': 'ED0002', 'LAT': 41.6742, 'LON': 26.553130600000003,
'NEIGH1': 0.0, 'NEIGH2': 46.67246190839837, 'NEIGH3': 197.84510783989847, 'NEIGH4': 197.11167463959035,
'NEIGH5': 203.62676166799767, 'NEIGH6': 202.10278985860108}, {'SC': 2, 'NETWORK_ID': 'ED0018', 'LAT': 41.26675,
'LON': 26.687669399999997, 'NEIGH1': 46.67246190839837, 'NEIGH2': 0.0, 'NEIGH3': 177.755266627054,
'NEIGH4': 173.5873416873924, 'NEIGH5': 183.86366943363294, 'NEIGH6': 180.37784680566605}, {'SC': 2,
'NETWORK_ID': 'IS0034', 'LAT': 41.10741944, 'LON': 28.80134167, 'NEIGH1': 197.84510783989847,
'NEIGH2': 177.755266627054, 'NEIGH3': 0.0, 'NEIGH4': 15.698318255306603, 'NEIGH5': 6.160917423948349,
'NEIGH6': 8.18216982054164}, {'SC': 2, 'NETWORK_ID': 'IS0063', 'LAT': 40.97868889, 'LON': 28.72448889,
'NEIGH1': 197.11167463959035, 'NEIGH2': 173.5873416873924, 'NEIGH3': 15.698318255306603, 'NEIGH4': 0.0,
'NEIGH5': 19.171910981439932, 'NEIGH6': 10.184673701884034}, {'SC': 2, 'NETWORK_ID': 'IS0280', 'LAT': 41.1085556,
'LON': 28.874861100000004, 'NEIGH1': 203.62676166799767, 'NEIGH2': 183.86366943363294, 'NEIGH3': 6.160917423948349,
'NEIGH4': 19.171910981439932, 'NEIGH5': 0.0, 'NEIGH6': 9.363881177252976}, {'SC': 2, 'NETWORK_ID': 'IS0880',
'LAT': 41.03519444, 'LON': 28.82001389, 'NEIGH1': 202.10278985860108, 'NEIGH2': 180.37784680566605,
'NEIGH3': 8.18216982054164, 'NEIGH4': 10.184673701884034, 'NEIGH5': 9.363881177252976, 'NEIGH6': 0.0},
{'SC': 3, 'NETWORK_ID': 'ED0018', 'LAT': 41.26675, 'LON': 26.687669399999997, 'NEIGH1': 0.0, 'NEIGH2': 182.51019908647177,
'NEIGH3': 177.755266627054, 'NEIGH4': 173.5873416873924, 'NEIGH5': 183.86366943363294, 'NEIGH6': ''}, {'SC': 3,
'NETWORK_ID': 'IB9048', 'LAT': 40.98021667, 'LON': 28.833175, 'NEIGH1': 182.51019908647177, 'NEIGH2': 0.0,
'NEIGH3': 14.394041790437557, 'NEIGH4': 9.125348535697553, 'NEIGH5': 14.692605425772422, 'NEIGH6': ''}, {'SC': 3,
'NETWORK_ID': 'IS0034', 'LAT': 41.10741944, 'LON': 28.80134167, 'NEIGH1': 177.755266627054, 'NEIGH2': 14.394041790437557,
'NEIGH3': 0.0, 'NEIGH4': 15.698318255306603, 'NEIGH5': 6.160917423948349, 'NEIGH6': ''},
{'SC': 3, 'NETWORK_ID': 'IS0063', 'LAT': 40.97868889, 'LON': 28.72448889, 'NEIGH1': 173.5873416873924,
'NEIGH2': 9.125348535697553, 'NEIGH3': 15.698318255306603, 'NEIGH4': 0.0, 'NEIGH5': 19.171910981439932, 'NEIGH6': ''},
{'SC': 3, 'NETWORK_ID': 'IS0280', 'LAT': 41.1085556, 'LON': 28.874861100000004, 'NEIGH1': 183.86366943363294,
'NEIGH2': 14.692605425772422, 'NEIGH3': 6.160917423948349, 'NEIGH4': 19.171910981439932, 'NEIGH5': 0.0, 'NEIGH6': ''}]
$ cat data.csv
SC,NETWORK_ID,LAT,LON,NEIGH1,NEIGH2,NEIGH3,NEIGH4,NEIGH5,NEIGH6
0,ED0002,41.6742,26.553130600000003,0.0,32.21502886502109,200.48599610361597,203.16353066879788,,
0,ED0016,41.7750556,26.9170278,32.21502886502109,0.0,176.95946212304386,180.60233416877116,,
0,IS0030,41.05455556,28.80925,200.48599610361597,176.95946212304386,0.0,8.739431576792299,,
0,IS0134,40.97616944,28.80165,203.16353066879788,180.60233416877116,8.739431576792299,0.0,,
1,ED0016,41.7750556,26.9170278,0.0,181.25721917309428,175.22169273308518,179.22877097784087,,
1,IS0096,40.99406111,28.82413056,181.25721917309428,0.0,8.003453963767388,13.423113789153426,,
1,IS0137,40.98033889,28.73052778,175.22169273308518,8.003453963767388,0.0,18.70230868984524,,
1,IS0280,41.1085556,28.874861100000004,179.22877097784087,13.423113789153426,18.70230868984524,0.0,,
2,ED0002,41.6742,26.553130600000003,0.0,46.67246190839837,197.84510783989847,197.11167463959035,203.62676166799767,202.10278985860108
2,ED0018,41.26675,26.687669399999997,46.67246190839837,0.0,177.755266627054,173.5873416873924,183.86366943363294,180.37784680566605
2,IS0034,41.10741944,28.80134167,197.84510783989847,177.755266627054,0.0,15.698318255306603,6.160917423948349,8.18216982054164
2,IS0063,40.97868889,28.72448889,197.11167463959035,173.5873416873924,15.698318255306603,0.0,19.171910981439932,10.184673701884034
2,IS0280,41.1085556,28.874861100000004,203.62676166799767,183.86366943363294,6.160917423948349,19.171910981439932,0.0,9.363881177252976
2,IS0880,41.03519444,28.82001389,202.10278985860108,180.37784680566605,8.18216982054164,10.184673701884034,9.363881177252976,0.0
3,ED0018,41.26675,26.687669399999997,0.0,182.51019908647177,177.755266627054,173.5873416873924,183.86366943363294,
3,IB9048,40.98021667,28.833175,182.51019908647177,0.0,14.394041790437557,9.125348535697553,14.692605425772422,
3,IS0034,41.10741944,28.80134167,177.755266627054,14.394041790437557,0.0,15.698318255306603,6.160917423948349,
3,IS0063,40.97868889,28.72448889,173.5873416873924,9.125348535697553,15.698318255306603,0.0,19.171910981439932,
3,IS0280,41.1085556,28.874861100000004,183.86366943363294,14.692605425772422,6.160917423948349,19.171910981439932,0.0,