删除列值 < 0 的 Pandas DataFrame 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19905927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delete Pandas DataFrame row where column value is < 0
提问by Lukas Spie?
I already read the answers in thisthread but it doesn't answer my exact problem. My DataFrame looks like this
我已经阅读了这个线程中的答案,但它没有回答我的确切问题。我的 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
Hyman 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.
我想删除 Michael Phillips 的行,因为他的相关值低于零。如前所述,我尝试了df = df[df.Correlation]和 的不同组合,df = df.drop()但找不到任何有效的组合。
回答by waitingkuo
df = df[df['Correlation'] >= 0]
回答by kina_re
df['Correlation'].drop(df[df['Correlation'] < 0].index, inplace=True)

