1

What is the proper solution in pandas to get the next timestamp value?

I have the following timestamp:

Timestamp('2017-11-01 00:00:00', freq='MS')

I want to get this as the result for the next timestamp value:

Timestamp('2017-12-01 00:00:00', freq='MS')

Edit:

I am working with multiple frequencies (1min, 5min, 15min, 60min, D, W-SUN, MS).

Is there a generic command to get next value?

Is the best approach to build a function that behaves accordingly to each one of the frequencies?

joaoavf
  • 1,343
  • 1
  • 12
  • 25

1 Answers1

3

General solution is convert strings to offset and add to timestamp:

L = ['1min', '5min', '15min', '60min', 'D', 'W-SUN', 'MS']

t = pd.Timestamp('2017-11-01 00:00:00', freq='MS')

t1 = [t + pd.tseries.frequencies.to_offset(x) for x in L]
print (t1)
[Timestamp('2017-11-01 00:01:00', freq='MS'), 
 Timestamp('2017-11-01 00:05:00', freq='MS'),
 Timestamp('2017-11-01 00:15:00', freq='MS'), 
 Timestamp('2017-11-01 01:00:00', freq='MS'),
 Timestamp('2017-11-02 00:00:00', freq='MS'), 
 Timestamp('2017-11-05 00:00:00'), 
 Timestamp('2017-12-01 00:00:00')]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252