I have a dataframe like:
Tag Class
A P
A Q
B P
B Q
C P
C Q
C R
I want to group by Tag and keep the first value from Class. However, if this value was used previously, look for the next value within the tag.
Expected output:
Tag Class
A P
B Q
C R
If there is no class left for the tag, then return null (or don't include Tag in output).
I have been trying to do this with drop_duplicates, but with no luck. How can I achieve this?