I have a following dataframe:
| Index | Time | User | Description |
|---|---|---|---|
| 1 | 27.10.2021 15:58:00 | [email protected] | Tab Alpha of type PARTSTUDIO opened by User A |
| 2 | 27.10.2021 15:59:00 | [email protected] | Start edit of part studio feature |
| 3 | 27.10.2021 15:59:00 | [email protected] | Cancel Operation |
| 4 | 27.10.2021 15:59:00 | [email protected] | Tab Alpha of type PARTSTUDIO opened by User B |
| 5 | 27.10.2021 15:59:00 | [email protected] | Start edit of part studio feature |
| 6 | 27.10.2021 16:03:00 | [email protected] | Cancel Operation |
| 7 | 27.10.2021 16:03:00 | [email protected] | Add assembly feature |
| 9 | 27.10.2021 16:03:00 | [email protected] | Tab Beta of type PARTSTUDIO opened by User A |
| 10 | 27.10.2021 16:15:00 | [email protected] | Start edit of part studio feature |
| 11 | 27.10.2021 16:15:00 | [email protected] | Start edit of part studio feature |
| 12 | 27.10.2021 16:15:00 | [email protected] | Tab Alpha of type PARTSTUDIO closed by User B |
| 14 | 27.10.2021 16:54:00 | [email protected] | Add assembly feature |
| 15 | 27.10.2021 16:55:00 | [email protected] | Tab Beta of type PARTSTUDIO closed by User A |
| 16 | 27.10.2021 16:55:00 | [email protected] | Start edit of part studio feature |
| 17 | 27.10.2021 16:55:00 | [email protected] | Tab Delta of type PARTSTUDIO closed by User B |
Expected output:
| Index | Time | User | Description |
|---|---|---|---|
| 1 | 27.10.2021 15:58:00 | [email protected] | Tab Alpha of type PARTSTUDIO opened by User A |
| 2 | 27.10.2021 15:59:00 | [email protected] | Start edit of part studio feature |
| 3 | 27.10.2021 15:59:00 | [email protected] | Cancel Operation |
| 4 | 27.10.2021 15:59:00 | [email protected] | Tab Alpha of type PARTSTUDIO opened by User B |
| 5 | 27.10.2021 15:59:00 | [email protected] | Start edit of part studio feature |
| 6 | 27.10.2021 16:03:00 | [email protected] | Cancel Operation |
| 7 | 27.10.2021 16:03:00 | [email protected] | Add assembly feature |
| 8 | 27.10.2021 16:03:00 | [email protected] | Tab Alpha of type PARTSTUDIO closed by User A |
| 9 | 27.10.2021 16:03:00 | [email protected] | Tab Beta of type PARTSTUDIO opened by User A |
| 10 | 27.10.2021 16:15:00 | [email protected] | Start edit of part studio feature |
| 11 | 27.10.2021 16:15:00 | [email protected] | Start edit of part studio feature |
| 12 | 27.10.2021 16:15:00 | [email protected] | Tab Alpha of type PARTSTUDIO closed by User B |
| 13 | 27.10.2021 16:15:00 | [email protected] | Tab Delta of type PARTSTUDIO opened by User B |
| 14 | 27.10.2021 16:54:00 | [email protected] | Add assembly feature |
| 15 | 27.10.2021 16:55:00 | [email protected] | Tab Beta of type PARTSTUDIO closed by User A |
| 16 | 27.10.2021 16:55:00 | [email protected] | Start edit of part studio feature |
| 17 | 27.10.2021 16:55:00 | [email protected] | Tab Delta of type PARTSTUDIO closed by User B |
How to iterate through dataframe and check if after each value "Tab x opened by User y" in the Description column, the "Tab x closed by User y" follows somewhere further in the dataframe? If yes OK. If not, if the "Tab zz opened by User A" follows, that means that "Tab x closed by User y" is missing and should be inserted a row before the "Tab zz opened by User A" value (example index 8). Same goes vice versa (index 13). Is there a way to do this without df.iterrows? Thanks in advance.