I want to get the multiple first occurrences of each group (ie: every time a group appears after another group), given that some groups may appear more than once in the data frame. For example:
| col1 | col2 |
|---|---|
| AAA | 111 |
| AAA | 222 |
| AAA | 444 |
| BBB | 111 |
| BBB | 333 |
| CCC | 777 |
| CCC | 333 |
| AAA | 888 |
| AAA | 777 |
I would like to return both "first" occurrences of the group AAA:
| col1 | col2 |
|---|---|
| AAA | 111 |
| BBB | 111 |
| CCC | 777 |
| AAA | 888 |
I've tried using groupby but it only returns the first occurrence after grouping. Is there a simple way to get this kind of result?