How can I get pandas timestamp for a certain number of months?

Suppose I have a Timestamp t1 object.

import pandas a pd t1=pd.Timestamp('2013-04-01 00:00:00') 

How can I get another pandas timestamp offset k months from t1?

+5
source share
1 answer

You can use relativedelta :

 In [135]: k=2 t1 + pd.datetools.relativedelta(months=k) Out[135]: Timestamp('2013-06-01 00:00:00') 

Or DateOffset :

 In [136]: k=2 t1 + pd.DateOffset(months=k) Out[136]: Timestamp('2013-06-01 00:00:00') 

Thanks to @AlexRiley for the proposed editing, relativedelta been moved to

pd.offsets.relativedelta since 0.20.0

+7
source

All Articles