I want to calculate the distance between two gps coordinates (the first and the last one for each tripId), to get the distance for each trip my dataframe looks like that
tripId latitude longitude timestamp
0 1817603 53.155273 8.207176 2021-05-24 00:29:22
1 1817603 53.155271 8.206898 2021-05-24 00:29:38
2 1817603 53.155213 8.206314 2021-05-24 00:29:44
3 1817603 53.155135 8.206429 2021-05-24 00:29:50
4 1817603 53.154950 8.206565 2021-05-24 00:29:56
... ... ... ... ...
195 1817888 53.092805 8.212095 2021-05-24 08:27:54
196 1817888 53.093024 8.211756 2021-05-24 08:27:59
197 1817888 53.093305 8.211383 2021-05-24 08:28:05
198 1817888 53.093594 8.211026 2021-05-24 08:28:10
199 1817888 53.093853 8.210708 2021-05-24 08:28:15
i did that for each step using s = pd.Series(haversine_vector(df, df.shift(),Unit.KILOMETERS), index=df.index, name='distance_K')
but i need to know the distance for the whole trip for each id
I have used this as a test and it works, but i need to know the exact duration for each trip (the final duration)
for i in range(1,df.shape[0]-1):
if df['tripId'][i]==df['tripId'][i+1]:
df['distance'][i]=df['distance'][i-1]+df['distance_K'][i]
else:
df['distance'][i]=df['distance_K'][i]