Supposing I have a dataframe like this:
| Date | is_start | is_end |
|---|---|---|
| 2021-07-16 10:40 | False | False |
| 2021-07-16 10:41 | False | False |
| 2021-07-16 10:42 | False | False |
| 2021-07-16 10:43 | True | False |
| 2021-07-16 10:44 | False | False |
| 2021-07-16 10:45 | False | True |
| 2021-07-16 10:46 | False | False |
| 2021-07-16 10:47 | True | False |
| 2021-07-16 10:48 | False | False |
| 2021-07-16 10:49 | False | False |
| 2021-07-16 10:50 | False | False |
| 2021-07-16 10:51 | False | True |
| 2021-07-16 10:52 | False | False |
| 2021-07-16 10:53 | False | False |
| 2021-07-16 10:54 | True | False |
| 2021-07-16 10:55 | False | False |
I would like to be able to use groupby (or something similar in terms of efficiency) to create groups of rows in between (and including) their respective is_start and is_end flags. E.g.:
Group 1
| Date | is_start | is_end |
|---|---|---|
| 2021-07-16 10:43 | True | False |
| 2021-07-16 10:44 | False | False |
| 2021-07-16 10:45 | False | True |
Group 2
| Date | is_start | is_end |
|---|---|---|
| 2021-07-16 10:47 | True | False |
| 2021-07-16 10:48 | False | False |
| 2021-07-16 10:49 | False | False |
| 2021-07-16 10:50 | False | False |
| 2021-07-16 10:51 | False | True |
I am hoping there is a solution to this without going down the route of looping with iterrows, but thus far, it’s eluding me.
Additionally...
(but not as important)
It would also be useful to have a way of separately identifying the unfinished group that starts at 2021-07-16 10:54