Mark Ginsburg
Mark Ginsburg

Reputation: 2269

Filtering a Pandas Dataframe with a boolean mask

How do I drop all dataframe rows that don't match a pair of conditions.

I did this:

df = df[ ! ((df['FVID'] == 0) & (df['vstDelta'] == 0)) ]

but that was a syntax error. Hopefully it illustrates what I want to do, which is to drop all records containing these 2 conditions.

Upvotes: 3

Views: 5904

Answers (1)

Allen Qin
Allen Qin

Reputation: 19957

You should use '~' instead of ! to get the negation of the condition.

df = df[~((df['FVID'] == 0) & (df['vstDelta'] == 0))]

Upvotes: 5

Related Questions