Home > other >  Python: Pandas Timedelta for one month
Python: Pandas Timedelta for one month

Time:09-29

Is there a way to do a Timedelta for one month?

Applying pd.Timedelta('1M') yields Timedelta('0 days 00:01:00').

Is there a code word for month?

CodePudding user response:

Timedelta is for absolute offsets. A month "offset", by definition, might have different lengths depending on the value it's applied to.

For those cases, you should use DateOffset:

pandas.DateOffset(months=1)

Functional example:

import pandas as pd
pd.Timestamp('2022-09-29 00:27:00')   pd.DateOffset(months=1)
>>> Timestamp('2022-10-29 00:27:00')
  • Related