I have a df like this:
frame = pd.DataFrame({\'a\' : [\'a,b,c\', \'a,c,f\', \'b,d,f\',\'a,z,c\']})
And a list of items:
let
IIUC, explode
and a boolean filter
the idea is to create a single series then we can groupby the index the count the true occurrences of your list using a cumulative sum
s = frame['a'].str.split(',').explode().isin(letters).groupby(level=0).cumsum()
print(s)
0 1.0
0 1.0
0 2.0
1 1.0
1 2.0
1 2.0
2 0.0
2 0.0
2 0.0
3 1.0
3 1.0
3 2.0
frame.loc[s[s.ge(2)].index.unique()]
out:
a
0 a,b,c
1 a,c,f
3 a,z,c