This week


Because we are focusing on the taxis movements, we would also like to know whenever the taxi has moved from a place to another between 2 different trips.

Here is an example:

Trips

We have these two trips where DOA is different than PUB, we would like to add a third trip C like this:

Intermediate Trips

C is Derived by the two trips A and B.

But when should we consider possible an intermediate trip like C?

We could start by defining some rules:

  1. B should not be already the next movement of the taxi after A, otherwise C would be a repetition of that trip
  2. The distance between DOA and PUB should be in a determined range of values
  3. The time between DT2 and DT3 should be in a determined range of values, the trips cannot be to short or to long
  4. The speed of the new trip should be feasible and into a valid range of values
  5. The medallion and the hack_license of A and B should be the same

Last week we have already defined good functions to compute trip_time, haversine_distance and speed; but these functions cannot operate of 2 different rows, what can we do?

Copy and shift

What we can do is simply make a copy of our dataframe, shift it by -1 and concatenate it with the original dataframe of valid_records.