Reputation: 335
I have a pandas dataframe (fb) with the date column orig_date. I want to add the number of months in the count_to_add column to the orig_date column, but the MonthEnd function isn't vectorized.
Here's what I tried:
fb["orig_date"] = fb["orig_date"] +
pd.tseries.offsets.MonthEnd(fb["count_to_add"])
Since the series count_to_add isn't an integer, the MonthEnd function errors out.
Upvotes: 0
Views: 103
Reputation: 432
If you want to add "number of months" only, use DateOffset instead.
fb['orig_date'] = fb.apply(lambda x: x['orig_date'] + pd.tseries.offsets.DateOffset(months=int(x['count_to_add'])), axis=1)
Upvotes: 1