Given this dataframe and set:
df = pd.DataFrame({'blah':['cats','cats','dogs','dogs','snakes','snakes','bears','bears'],
'foo':['A', 'B', 'B', 'A', 'A', 'B', 'A', 'A']})
blah foo
0 cats A
1 cats B
2 dogs B
3 dogs A
4 snakes A
5 snakes B
6 bears A
7 bears A
letters = set(['A', 'B'])
{'A', 'B'}
I want to filter the dataframe so that it includes only groups of blah where set(foo) does not match letters.
My expected result is:
blah foo
6 bears A
7 bears A
Below is the closest thing I've got, but I can't figure out how to compare to letters, and I don't want to return a DataFrame and not a Series.
df.groupby('blah')['foo'].apply(set)