I have the following pandas dataframe:
df =
A B C
111-ABC 123 EEE
111-ABC 222 EEE
111-ABC 444 XXX
222-CCC 222 YYY
222-CCC 333 67T
333-DDD 123 TTT
333-DDD 123 BTB
333-DDD 444 XXX
333-DDD 555 AAA
I want to delete all row groups (grouped by A) that do not contain 123in the column B.
The expected result is one (row group 222-CCCdeleted):
result =
A B C
111-ABC 123 EEE
111-ABC 222 EEE
111-ABC 444 XXX
333-DDD 123 TTT
333-DDD 123 BTB
333-DDD 444 AAA
How to do it? I suggest that you should use it first groupby, but how do I filter groups of strings, not just specific strings?
result = df.groupby("A").... ??
source
share