2

I have a data frame with a date time index where index values are non unique (see last two index values).

I would like to get the next valid index value given a time delta of +5 seconds from the first index value. In the case below, the first index value = '2018-12-03 08:00:00.410' and adding 5 seconds to that would result in '2018-12-03 08:00:05.410'. The next valid index value would be '2018-12-03 08:00:08.680'.

                                  ID       PRICE 
DATETIME                                             
2018-12-03 08:00:00.410            1       3229.0
2018-12-03 08:00:00.550            1       3229.0
2018-12-03 08:00:00.630            1       3229.0
2018-12-03 08:00:08.680            1       3230.0
2018-12-03 08:00:08.680            1       3230.0

I tried to apply

idx = df.index[df.index.get_loc('2018-12-03 08:00:05.410', method='bfill')]

but I get Exception has occurred: InvalidIndexError Reindexing only valid with uniquely valued Index objects

How can I get the index value knowing it is non-unique?

finstats
  • 1,349
  • 4
  • 19
  • 31

1 Answers1

0
df.index[df.index.duplicated()].tolist()