1
$\begingroup$

I have time series data like this:

date longitude latitude
01/01/2010 -5.42766 107.5784
02/01/2010 -6.42728 104.5245
07/01/2010 -7.42702 105.5816
14/01/2010 -4.42728 99.57834
17/01/2010 -6.41523 103.5562
... ... ...
31/12/2013 -4.42728 99.57834

This is location data (longitude and latitude). I want to change the data from daily to weekly, something like this:

week longitude latitude
week 1 ... ...
week 2 ... ...
week 3 ... ...
week 4 ... ...

how to transform the data? since calculating the mean of the data doesn't make sense because it is location data.

$\endgroup$
0

2 Answers 2

1
$\begingroup$

I don't know exactly whether it is useful for your case, but you can use last day of the week, so coordinates of the object at end of the week.

I copied your example data to a text file, read it with Pandas, and resampled data from daily to weekly by getting coordinates of the last day of each week.

df = pd.read_csv('untitled.txt', 
                 infer_datetime_format=True, 
                 parse_dates=['date'], dayfirst=True)
df.set_index('date', inplace=True)
df.resample('W').last()
$\endgroup$
3
  • 1
    $\begingroup$ Ok thanks, is it OK to just discard the rest of the data? is there any reference (paper, book, etc) for this to be OK to do? $\endgroup$ May 4, 2021 at 9:10
  • 1
    $\begingroup$ To convert daily data to weekly data you should downsample it. You can try different methods like getting first day, the day in the middle of the week, distance taken between first day of the week and last day of the week, even you can try mean. You should apply this in weekly windows to convert daily data to weekly data. It really depends on characteristics of your problem. Then if you're making a predictive model you can compare metrics you obtained by applying each different approach. $\endgroup$
    – tkarahan
    May 4, 2021 at 9:42
  • $\begingroup$ Yes, I want to build a predictive model, so I can use different approaches and see which one is the best then? $\endgroup$ May 17, 2021 at 5:46
0
$\begingroup$

So the question is truly about how to aggregate the data to answer your question, and that has little to do with the fact that you are working with geolocation data, and a lot more with the question you are trying to answer. Let me make some examples:

  • you are a marine scientist who tagged a single whale you are following daily in her journey across our planet oceans. On a weekly basis, you probably want to know the distance traveled in a week. You compute then the (Haversine) distance between the lat/lon on the first, and the last day of the week. Or better, for each week you want to record initial location, distance traveled, final location.

  • you are a business intelligence analysts who is recording all users that log on your app. Your manager is curious to know what region your users mostly come from. You can then choose to aggregate all different locations in a list to then display as a heatmap, or maybe just average them out to give you the "center" of the region with most users.

  • you are add a persona who is recording this data for some other reason and just came up with a new question to throw at this data hence you need to use problem-specific aggregation

$\endgroup$
2
  • $\begingroup$ My problem is I want to build a time series forecasting model to predict the next location (longitude and latitude, each have its own model, I use ARIMA) on a weekly basis, what problem-specific aggregation would you recommend then? to convert my daily data into weekly data $\endgroup$ May 17, 2021 at 5:44
  • $\begingroup$ Then your question is really "what do I have a good reason to think will predict the next location?". But that again, it depends on next location of what. In particular, for an inorganic object good predictors may be just position and speed along a known trajectory. For a living creature, predictors would likely depend on incentives and mean of transport (food location and fairly regular speed for animals, jobs/attractions and means-dependent speed for humans) $\endgroup$
    – famargar
    May 17, 2021 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.