Home > Enterprise >  Pandas calculating the speed between two rows based on timestamp and coordinates
Pandas calculating the speed between two rows based on timestamp and coordinates

Time:07-01

Given a pandas dataframe like:

timestamp  latitude  longitude
1652846403129   30   20
1652846415130   31   21
1652846427128   32   22
1652846439128   33   23

How could I calculate the "speed" between two rows and have it as a new column? I would have to calculate the distance based on the coordinates and divide by time taken.

I have a function that calculates distance between two coordinates, but it takes two tuples of form (lat,long) as input.

rolling.apply seemed like an option so that I can work on windows of two, but I can't quite get it to work and it seemed only to work on one series at a time. Something like creating a new column with shifting doesn't seem to work either since the function for distance that I'm using doesn't support the use of dataframes.

CodePudding user response:

You can use the enter image description here

  • Related