I have the following data :
Trip Start_Lat Start_Long End_lat End_Long Starting_point Ending_point
Trip_1 56.5624 -85.56845 58.568 45.568 A B
Trip_1 58.568 45.568 -200.568 -290.568 B C
Trip_1 -200.568 -290.568 56.5624 -85.56845 C D
Trip_2 56.5624 -85.56845 -85.56845 -200.568 A B
Trip_2 -85.56845 -200.568 -150.568 -190.568 B C
I would like to find the circuitry which is
Circuity = Total Distance Travelled(Trip A+B+C+D) - Straight line (Trip A to D)
-----------------------------------------------------------------------
Total Distance Traveled (Trip A+B+C+D)
I tried the following code,
df['Distance']= df['flight_distance'] = df.apply(lambda x: great_circle((x['start_lat'], x['start_long']), (x['end_lat'], x['end_long'])).km, axis = 1)
df['Total_Distance'] = ((df.groupby('Trip')['distance'].shift(2) +['distance'].shift(1) + df['distance']).abs())
Could you help me to find the straight line distance and circuitry?
UPDATE:
you may want to convert your values to numeric dtypes first:
IIUC you can do it this way:
Result: