I often see the ~
operator used in pandas statements by people offering help on stackoverflow, but I can't think of any time where I've needed to use it because !=
just naturally comes to mind for me first. So I'm wondering why it exists.
For example, this statement:
(df['col_A'] > 100) & ~(df['col_A'] == 120)
... could just as easily be written as:
(df['col_A'] > 100) & (df['col_A'] != 120)
I imagine there must be situations where one must use ~
, but what are they?