MathMan 99
MathMan 99

Reputation: 755

Python: Pandas Timedelta for one month

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?

Upvotes: 6

Views: 3229

Answers (1)

dataista
dataista

Reputation: 3457

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')

Upvotes: 6

Related Questions