删除Pandas DataFrame中列值小于0的行

8

我已经阅读了这个帖子中的答案,但它并没有解决我的确切问题。 我的DataFrame看起来像这样:

                      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

我希望删除Michael Phillips的行,因为他的相关系数值低于零。正如所说,我尝试了不同的组合df = df[df.Correlation]df = df.drop()但是没有找到有效的方法。

2个回答

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接