Reputation: 35
I am trying to create a new column in my data frame by adding 6 months to the date column.
df_main['m1'] = df_main['date'] + relativedelta(months=6)
df_main['date'] is of the format datetime64[ns] I tried converting it to timedelta64[ns] still doesn't work.
Example df_main['date'] = 2019-04-01
Upvotes: 2
Views: 396
Reputation: 169414
Instead do:
df['x'].dt.date + dateutil.relativedelta.relativedelta(months=6)
Or a more long-winded -- and slower -- way:
df_main['m1'] = df_main['date'].apply(lambda x: x + relativedelta(months=6))
Upvotes: 2