title: Determine if point is moving (pandas window function)
body: <p>I've got a dataset (pandas dataframe) of multiple people that have a gps device and have tracked their location over time. This dataset looks something like this:</p>
  
  <pre><code>person_id | timestamp               | latitude | longitude
  1         | 2019-05-15 10:01:53.231 | 10.00110 | 5.64321
  1         | 2019-05-15 10:02:54.131 | 10.00310 | 5.64322
  1         | 2019-05-15 10:03:55.331 | 10.00210 | 5.64325
  1         | 2019-05-15 10:05:00.731 | 10.00410 | 5.64421
  1         | 2019-05-15 10:06:48.434 | 10.00510 | 5.64121
  1         | 2019-05-15 10:07:24.189 | 10.01110 | 5.63321
  1         | 2019-05-15 10:08:53.231 | 10.02110 | 5.62821
  2         | 2019-05-15 10:02:41.111 | 10.01131 | 5.64320
  2         | 2019-05-15 10:03:47.221 | 10.01132 | 5.64322
  2         | 2019-05-15 10:05:53.121 | 10.01130 | 5.64321
  2         | 2019-05-15 10:07:24.564 | 10.01401 | 5.64331
  etc.
  </code></pre>
  
  <p>So the GPS devices measure their location frequently. Sometimes we miss a few points, but in general the dataset is quite good. The GPS coordinates however jump around a bit even if you are not moving due to the accuracy of the device/GPS.</p>
  
  <p>What I want to do is to add a column that indicates whether a person is moving or not. To do so I thought of having a rolling window, calculate the mean position in that window and then calculate the distance (geopy.distance.distance()) to that position and if the distance of any of the points in the window is larger than a given threshold (say 15m) than those points are considered to be "moving".</p>
  
  <p>I've looked around on the internet but can't really find out how to do this (without using inefficient for loops). I would be looking into something like such:</p>
  
  <pre><code>df['moving'] = df.groupby(['mmsi']).rolling(
      window=10).apply(
          ... some function here, like:
          np.any([distance(
              lat_mean,
              lon_mean,
              row_lat,
              row_lon
          ) for row in window] &gt; threshold))
  </code></pre>
  
  <p>Ideally we would want to have the window based on time and a minimum of datapoints, but this might make it more difficult...
  Any suggestions/ideas?</p>