Working with the following formula and resulting dataframe:
df['dist'] = haversine(df.LAT.shift(), df.LONG.shift(),df.loc[1:, 'LAT'], df.loc[1:, 'LONG'])
The haversine function is defined here: https://stackoverflow.com/a/40453439/15492238
Group ID LAT LONG dist
1 1 74.166061 30.512811 NaN
1 2 72.249672 33.427724 232.549785
1 3 67.499828 37.937264 554.905446
1 4 84.253715 69.328767 1981.896491
2 5 72.104828 33.823462 1513.397997
2 6 63.989462 51.918173 1164.481327
2 7 80.209112 33.530778 1887.256899
2 8 68.954132 35.981256 1252.531365
2 9 83.378214 40.619652 1606.340727
2 10 68.778571 6.607066 1793.921854
I want to rewrite the same formula but group them by them group column.
Expected output:
Group ID LAT LONG dist
1 1 74.166061 30.512811 NaN
1 2 72.249672 33.427724 232.549785
1 3 67.499828 37.937264 554.905446
1 4 84.253715 69.328767 1981.896491
2 5 72.104828 33.823462 NaN
2 6 63.989462 51.918173 1164.481327
2 7 80.209112 33.530778 1887.256899
2 8 68.954132 35.981256 1252.531365
2 9 83.378214 40.619652 1606.340727
2 10 68.778571 6.607066 1793.921854