Suppose I have a pandas Timestamp object t1.
import pandas a pd t1=pd.Timestamp('2013-04-01 00:00:00')
How can I get another pandas timestamp, offset by k months from t1?
You can use relativedelta:
relativedelta
In [135]: k=2 t1 + pd.datetools.relativedelta(months=k) Out[135]: Timestamp('2013-06-01 00:00:00')
Or DateOffset:
DateOffset
In [136]: k=2 t1 + pd.DateOffset(months=k) Out[136]: Timestamp('2013-06-01 00:00:00')
Thanks to @AlexRiley for the suggested edit, relativedelta has been moved to
pd.offsets.relativedelta since 0.20.0
pd.offsets.relativedelta
0.20.0
1.4m articles
1.4m replys
5 comments
57.0k users