I would try explaining my problem by taking a sample data
ID Region Start_Date End_Date
1 Reg1 27/1/2017 27/1/2017
2 Reg1 27/2/2017 05/3/2017
1 Reg1 24/3/2017 25/5/2017
Now I want to outcome to be something like this:
ID Region n_Start_Date n_End_Date
1 Reg1 27/1/2017 27/1/2017
2 Reg2 27/2/2017 28/2/2017
2 Reg2 01/3/2017 05/3/2017
1 Reg1 24/3/2017 31/3/2017
1 Reg1 01/4/2017 30/4/2017
1 Reg1 01/5/2017 31/5/2017
Current Approach which I'm thinking of implementing:
I've created a dataframe which has 14 records with every month start date and end date for year 2017 and 2018 like:
Year Month Start of Month End of Month
2017 1 1/1/2017 31/1/2017
2017 2 1/2/2017 28/2/2017
2017 3 1/3/2017 31/3/2017
2017 4 1/4/2017 30/4/2017
2017 5 1/5/2017 31/5/2017
2017 6 1/6/2017 30/6/2017
2017 7 1/7/2017 31/7/2017
2017 8 1/8/2017 31/8/2017
2017 9 1/9/2017 30/9/2017
2017 10 1/10/2017 31/10/2017
2017 11 1/11/2017 30/11/2017
2017 12 1/12/2017 31/12/2017
2018 1 2/12/2017 31/1/2018
2018 2 3/12/2017 28/2/2018
I've made a new column for year and month:
If the start date year, Month are same as that of end date year, month then next same start and end date would be copied to the new dataframe like
ID Region Start_Date End_Date n_Start_Date n_End_Date 1 Reg1 27/1/2017 27/1/2017 27/1/2017 27/1/2017If the Start date year, Month are not same then it appends
ID Region Start_Date End_Date n_Start_Date n_End_Date 2 Reg2 27/2/2017 05/3/2017 27/2/2017 28/2/2017 2 Reg2 27/2/2017 05/3/2017 01/3/2017 05/3/2017
I couldn't find any similar questions, I've gone through this link, but not useful.
if there is any better approach do let me know.