Home > database >  TypeError: unsupported operand type(s) for : 'DatetimeArray' and 'relativedelta'
TypeError: unsupported operand type(s) for : 'DatetimeArray' and 'relativedelta'

Time:11-18

I am trying to convert a column called Month_Next from a dataframe called df_actual from the last day of one month to the first day of the next. The column looks like this:

enter image description here

And I'm using

df_actual.Month_Next = pd.to_datetime(df_actual.Month_Next)   relativedelta(months=1, day=1)

and getting this error.

TypeError: unsupported operand type(s) for  : 'DatetimeArray' and 'relativedelta'

Which makes no sense to me since this exact code works in a different notebook where Month_Next comes in as I believe a Timestamp object like so

enter image description here

Any ideas as to what's going on here?

CodePudding user response:

You are trying to add date types from different packages - one from pandas and the other dateutil. Try converting them to pandas types (use pandas.Timedelta).

CodePudding user response:

This works just fine:

Month_Next = df_actual.AsOfDate   pd.DateOffset(months =1) - pd.offsets.MonthBegin(1)
  • Related