Pandas: Inverse of boolean
In pandas, you can use the tilde (~) to flip bool values:
>>> df = pd.DataFrame({"A": ["Hello", "this", "World", "apple"]})
>>> df[df.A.str.contains("Hello|World")]
A
0 Hello
2 World
>>> df[~df.A.str.contains("Hello|World")]
A
1 this
3 apple
Via Stack Overflow.
Leave a comment