I have monthly performance of students for several years for all subjects. DataFrame has following columns: [Name, Subject, Month, Year, Marks] as given in following image 1:
Name Month Year Subject Marks
0 A 1 2022 Math 80
1 A 2 2022 Math 80
2 A 3 2022 Math 80
3 A 4 2022 Math 70
4 A 5 2022 Math 80
5 A 6 2022 Math 80
6 A 7 2022 Math 80
Now I want combine consecutive rows having same performance for given student and subject. As given in following image:
Name Subject Marks Time_Period
0 A Math 80 1.2022-3.2022
1 A Math 70 4.2022-4.2022
2 A Math 80 5.2022-7.2022
I have tried to group dataframe and extract Min/Max(Month) and Min/Max(Year). But it will give wrong result if student has different performance in month in between.