I'm looking to flatten certain processes. Basically looking at duplicates that are right after each other. Let's say I have a dataframe:
d = {'time': [12-08-2020, 13-08-2020, 14-08-2020, 15-08-2020, 16-08-2020], 'state': [off, on, on, on, off]}
df = pd.DataFrame(data=d)
Then I would use time.shift() to create the "time_end" column. Basically the next rows time. result:
time state time_end
0 12-08-2020 off 13-08-2020
1 13-08-2020 on 14-08-2020
2 14-08-2020 on 15-08-2020
3 15-08-2020 on 16-08-2020
4 16-08-2020 off NaN
My question is now, how do I flatten it so that it becomes in actuality 3 lines like this:
time state time_end
0 12-08-2020 off 13-08-2020
1 13-08-2020 on 16-08-2020
4 16-08-2020 off NaN
For my code I dont need repeat on's if they are followed by another on. Any help would be appreciated.