How would you update the coordinates based on teh date_recorded. For example, there is no observation for 6/27 but if I can assume both cars are driving in the same direction and rate as the last observation, how would I update to calculate distance using the lat/lng for the most recent date_recorded?
import pandas as pd
# Car 1
car1_data = {
'id': ['id0120169', 'id0386349', 'id1962532', 'id0335207', 'id0273508'],
'date_recorded': ['7/1/2016 9:05', '6/29/2016 22:26', '6/29/2016 2:47', '6/26/2016 22:29', '6/25/2016 19:19'],
'longitude': [-73.99017334, -73.97213745, -73.91963959, -73.98487091, -73.99116516],
'latitude': [40.75667953, 40.75746155, 40.80377579, 40.76160812, 40.75000763],
'rate': [50, 67, 43, 35, 46],
'direction': ['N', 'E', 'E', 'S', 'W']}
car1_df = pd.DataFrame(car1_data)
# Car 2
car2_data = {
'id': ['id2681896', 'id3308448', 'id2108525', 'id3952220', 'id2771348'],
'date_recorded': ['6/30/2016 23:59', '6/29/2016 19:33', '6/28/2016 20:50', '6/26/2016 21:07', '6/25/2016 18:46'],
'longitude': [-73.9881286621093, -73.9656295776367, -73.9716567993164, -73.9820938110351, -73.9761657714843],
'latitude': [40.7320289611816, 40.7527198791503, 40.7945442199707, 40.7694053649902, 40.7602424621582],
'rate': [81, 76, 59, 48, 55],
'direction': ['S', 'E', 'N', 'W', 'W']}
car2_df = pd.DataFrame(car2_data)
What you need to do is calculate the movement of each car based on its last observed direction and rate. If we assume both cars move in its last observed direction for 24 hours from its last observation before 6/27.
So given your data:
you should defined the following functions that update the position and predict the position relative the previous one:
So, for the desired date:
you'll get for car1
and for car 2