Im new to python and came across a code snippet.
df = df[~df['InvoiceNo'].str.contains('C')]
Would be much obliged if I could know whats the tilde signs usage in this context ?
Im new to python and came across a code snippet.
df = df[~df['InvoiceNo'].str.contains('C')]
Would be much obliged if I could know whats the tilde signs usage in this context ?
It means bitwise not, inversing boolean mask -
False
s toTrue
s andTrue
s toFalse
s.Sample:
Filter by
boolean indexing
:So output is all rows of DataFrame, which not contains
C
in columnInvoiceNo
.It's used to invert boolean Series, see pandas-doc.