To create a DateOffset, use the DateOffset() method in Pandas. Set the Increment value as an argument.
At first, import the required libraries −
from pandas.tseries.offsets import DateOffset import pandas as pd
Set the timestamp object in Pandas −
timestamp = pd.Timestamp('2021-09-11 02:30:55')
DateOffset for date increment. We are incrementing the months here using the "months" parameter −
print("DateOffset...\n",timestamp + DateOffset(months=2))
Example
Following is the code −
from pandas.tseries.offsets import DateOffset import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-09-11 02:30:55') # Display the Timestamp print("Timestamp...\n",timestamp) # DateOffset for date increment # We are incrementing the months here using the "months" parameter print("DateOffset...\n",timestamp + DateOffset(months=2))
Output
This will produce the following code −
Timestamp... 2021-09-11 02:30:55 DateOffset... 2021-11-11 02:30:55