Q:

Pandas deleting rows in order

Given a particular df:
ID Text
1  abc
1  xyz
2  xyz
2  abc
3  xyz
3  abc
3  ijk
4  xyz

I want to apply condition where: Grouping by ID, if abc exists then delete row with xyz.  The outcome would be:
ID Text
1  abc
2  abc
3  abc
3  ijk
4  xyz

Usually I would group them by Id and apply np.where(...).  However, I don't think this approach would work for this case since it's based on rows.
Many thanks!

A:

To the best of my knowledge, you can vectorize this with a groupby + transform:
df[~(df.Text.eq('abc').groupby(df.ID).transform('any') & df.Text.eq('xyz'))]

   ID Text
0   1  abc
3   2  abc
5   3  abc
6   3  ijk
7   4  xyz

