Lukas Spieß
Lukas Spieß

Reputation: 2468

Delete Pandas DataFrame row where column value is < 0

I already read the answers in this thread but it doesn't answer my exact problem. My DataFrame looks like this

                      Lady in the Water  The Night Listener  Just My Luck  Correlation
Claudia Puig                    NaN                 4.5           3.0     0.893405
Gene Seymour                    3.0                 3.0           1.5     0.381246
Jack Matthews                   3.0                 3.0           NaN     0.662849
Lisa Rose                       2.5                 3.0           3.0     0.991241
Michael Phillips                2.5                 4.0           NaN    -1.000000
Mick LaSalle                    3.0                 3.0           2.0     0.924473

and i want to delete Michael Phillips' row since his correlation value is below zero. As said, I tried different combinations of df = df[df.Correlation] and df = df.drop()but couldn't find anything that worked.

Upvotes: 8

Views: 25622

Answers (2)

kina_re
kina_re

Reputation: 41

df['Correlation'].drop(df[df['Correlation'] < 0].index, inplace=True)

Upvotes: 2

waitingkuo
waitingkuo

Reputation: 93904

df = df[df['Correlation'] >= 0]

Upvotes: 28

Related Questions