I have a dataframe which has two date columns:
Date1 Date2
2018-10-02 2018-12-21
2019-01-20 2019-04-30
and so on
I want to create a third column which basically is a column containing all the months between the two dates, something like this:
Date1 Date2 months
2018-10-02 2018-12-21 201810
2018-10-02 2018-12-21 201811
2018-10-02 2018-12-21 201812
2019-01-20 2019-04-30 201901
2019-01-20 2019-04-30 201902
2019-01-20 2019-04-30 201903
2019-01-20 2019-04-30 201904
How can i do this? I tried using this formula:
df['months']=df.apply(lambda x: pd.date_range(x.Date1,x.Date2, freq='MS').strftime("%Y%m"))
but i am not getting the desired result. Kindly help. Thanks