0

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.

forest
  • 315
  • 4
  • 14
  • See a relevant question [here](https://stackoverflow.com/questions/44003107/pandas-vectorized-date-offset-operations-with-vector-of-differing-offsets). – ayhan Aug 03 '17 at 22:41

1 Answers1

1

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)
Wonjin
  • 432
  • 3
  • 11