0

I have an data frame like this

ID   |  priority     |    latitude    |   longitude
412  |     1         |    36.67495    |   34.36598056
412  |     2         |    39.88226389 |   44.04348611
412  |     3         |    39.94746667 |   31.35788230
764  |     1         |    39.94746667 |   44.07428056
764  |     2         |    39.88226389 |   43.98109444
764  |     3         |    36.67495    |   32.46473056

What i want to do here, for each ID , i want to average calculate distance from 1st priority to 2nd and 3rd.

Example for 412 ID

I have a function which is calculates distance between 2 point.

km = distance_calc(lat1,lon1,latx,lonx)



distance_calc(36.67495,34.36598056,39.88226389,44.04348611)
distance_calc(36.67495,34.36598056,39.94746667,31.35788230)

This operation will repeat for each IDs and i will take average for all distances. I solved this problem with dataframe row iteration but this method is very very slow.

Beyhan Gul
  • 1,191
  • 1
  • 15
  • 25
  • 2
    Depends what your distance calculation is. Can you use this [vectorized Haversine formula](https://stackoverflow.com/a/29546836/4333359)? If so you could do a big merge of all rows within ID, dropping rows that merge with themself, apply that formla to the DataFrame then groupby + mean – ALollz Apr 03 '20 at 18:47
  • yes, i'm using haversine formula to calculate distance and it's already written.distance_calc function is ok. i want to calculate mean distance for each ID to their other priority points – Beyhan Gul Apr 03 '20 at 18:49

0 Answers0