I have a dataframe in the following format with ID's and A/B's. The dataframe is very long, over 3000 ID's.
id | type |
---|---|
1 | A |
2 | B |
3 | A |
4 | A |
5 | B |
6 | A |
7 | B |
8 | A |
9 | B |
10 | A |
11 | A |
12 | A |
13 | B |
... | ... |
I need to remove all rows (A+B), where more than one A is behind another one or more. So I dont want to remove the duplicates. If there are a duplicate (2 or more A's), i want to remove all A's and the B until the next A.
id | type |
---|---|
1 | A |
2 | B |
6 | A |
7 | B |
8 | A |
9 | B |
... | ... |
Do I need a loop for this problem? I hope for any help,thank you!