I would like to filter based on a string condition.
My dataframe looks like this:
I want to group by Id, and filter for groups that consist of both words: "add" and "set". Additional elements like close do not matter. I only want to filter groups with "set" and "add.
My final output should look like this:
I've tried this:
df = df.groupby(['id']).filter(lambda x: (x.mode == "set" & x.mode == "add").all())
But this wil give me an error message: unsupported operand type(s) for &: 'str' and 'method'
Let me know of other solutions. Thanks!