I am trying to generate last day of the month for a date field in my dataframe:
so there is field start date, I want to add say 5 columns like
nep_0, nep_1, nep_2, nep_3, nep_4.
So for nep_0 logic is as below:
last day ( policy start date+ relative months (0))
For nep_1:
last day(policy start date+ relative months (1)).
Was using this:
date_after_month =pol_start_date + relativedelta(months=i) nep_date=datetime.datetime(date_after_month.year,date_after_month.month,calendar.monthrange(date_after_month.year, date_after_month.month)[1])
But this used to iterate through each row of the data frame. My data frame has 1.5 million rows and it is taking a lot of time. can you tell me a better way to achieve the same. may be using apply or map.
I would also like these columns (nep_0, nep_1) to be created dynamically as in not passing relative months argument of 0,1,2,. they should also be looped through.
You can use
MonthEndandrollforward:Testing:
Now let's use Monthend:
Out::