DSouthy
DSouthy

Reputation: 189

Deleting DF rows in Pandas based on different column values

I have the following DF:

enter image description here

I want to remove all rows whereby TO and GP columns are negative and '0', and remove all rows whereby TTS and BMI columns are positive and '0'.

I have tried creating code like the following for each column however this is also deleting rows that are null which I do not want:

df [df ['GP'] >= 0]

What's the most efficient way to do this?

Upvotes: 0

Views: 37

Answers (1)

IoaTzimas
IoaTzimas

Reputation: 10624

Try with df.drop:

df.drop(df[(df.TO <= 0)  | (df.GP <=0) | (df.TS >= 0) | (df.BMI >=0)].index, inplace=True)

Upvotes: 1

Related Questions