Let's say I have a list of of timestamps and associated indices of some event. I have M timestamps which are not evenly spaced. I would like to downsample this list to N < M in such a way that my timestamps will be more or less equally spaced, i.e I don't want to just take first N from M.
timestamps =
[(Timestamp('2013-10-05 12:52:00+0000', tz='UTC'), 0),
(Timestamp('2013-10-07 18:38:00+0000', tz='UTC'), 1),
(Timestamp('2013-10-12 11:30:00+0000', tz='UTC'), 5),
(Timestamp('2013-10-13 11:58:00+0000', tz='UTC'), 7),
(Timestamp('2013-10-14 17:26:00+0000', tz='UTC'), 11),
(Timestamp('2013-10-16 17:54:00+0000', tz='UTC'), 12),
(Timestamp('2013-10-17 21:26:00+0000', tz='UTC'), 14),
(Timestamp('2013-10-20 13:37:00+0000', tz='UTC'), 17),
(Timestamp('2013-10-22 18:16:00+0000', tz='UTC'), 18),
(Timestamp('2013-10-25 23:37:00+0000', tz='UTC'), 19),
(Timestamp('2013-10-26 13:36:00+0000', tz='UTC'), 20),
(Timestamp('2013-10-30 19:11:00+0000', tz='UTC'), 26),
(Timestamp('2013-11-07 21:13:00+0000', tz='UTC'), 28),
(Timestamp('2013-11-08 13:16:00+0000', tz='UTC'), 29),
(Timestamp('2013-11-15 18:19:00+0000', tz='UTC'), 32),
(Timestamp('2013-11-16 00:27:00+0000', tz='UTC'), 33),
(Timestamp('2013-11-16 18:55:00+0000', tz='UTC'), 35),
(Timestamp('2013-12-04 16:58:00+0000', tz='UTC'), 40),
(Timestamp('2013-12-18 09:48:00+0000', tz='UTC'), 47),
(Timestamp('2013-12-19 08:32:00+0000', tz='UTC'), 50)]
let's say M=20
like in the example above and and N=15
. Is there any smart/known way to do this? The only thing that comes to my mind is calculating timedelta between each timestamp and then trying to do some search/optimization/genetic algorithm based on maximising median timedelta so that we dont get multiple points that are very close in time and some that are far away. Another option could be to generate N equally spaced points between start and end and try to match the closest existing ones to the artificial ones. I looked into pandas resample but it does not downsample the way I want, I need an exact N
number of elements to be left in my list. Any ideas, tips appreciated.