user1017373 user1017373 - 1 year ago 92
Python Question

Does Pandas have notin function to filter rows from data frame from a given list

I have a data frame and I need to get the rows which are

"no in"
the given list
I know in order to get the rows from the list we can use
isin.(list)
, so my question is whether there is a contrary "notin" function?

Answer Source

You can use the ~ in front of condition to negate it.

~df['Col1'].isin(list)

df['Col1'].isin(list) will return True/False, then just flip the boolean to get True where Col1 is not in the list.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download