Python Puzzle - measuring velocity
I have a csv with the following columns: 1. ID 2. Time - includes a date and exact time (minutes and such) 3. Latitude 4. Longitude Now, the data is from a mobile phone and represents movement. I am writing a script, an algorithm to solve the following puzzle. I want to calculate the velocity of the movement. To do that, I need to calculate the distance according to the lat and longitude. Each ID represents a mobile phone but it stays the same during different activities. By activity I mean a movement. So, let's say you had a walk in the morning and a run in the evening. They are under the same ID but different times. So, in my loop, I need to also separate according to time. The issue with the date column is that I probably have to separate it into two rows or maybe I don't have to? So, I know how to calculate the distance between two points (and velocity is easy) but I need to add it up according to the ID and the timing. So, in order to solve the issue with the different activities by the same ID (walk in the morning and afternoon, evening, etc.), I need to add a condition that time in row += 1 should be between 1 minute and 5 minutes difference (or something like that). I think my best option is to groupby id and time via pandas. import geopy.distance import pandas as pd import matplotlib.pyplot as plt # coords_1 = (52.2296756, 21.0122287) # coords_2 = (52.406374, 16.9251681) def calc_minutes(time_end, time_start): duration = (time_end - time_start).seconds minutes = duration/60 return minutes def calc_velocity(dist_km, time_start, time_end): """Return 0 if time_start == time_end, avoid dividing by 0""" if time_end > time_start: duration = (time_end - time_start).seconds return dist_km / duration else: return 0 def calculate_distance(lat1, lon1, lat2, lon2): coords_1 = (lat1, lon1) coords_2 = (lat2, lon2) d = geopy.distance.vincenty(coords_1, coords_2).km return d *Continuation