You are almost there, you just did not get the syntax exactly right, it should be:
df[(df.str.contains("b") == True) & (df.str.contains("a") == False)]
Another approach, which may be cleaner if you have many conditions to apply, is to link your filters along with a shrink or a loop:
from functools import reduce
filters = [("a", False), ("b", True)]
reduce(lambda df, f: df[df.str.contains(f[0]) == f[1]], filters, df)
source
share