删除python中小于某个值的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41800424/
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
Remove rows in python less than a certain value
提问by JAG2024
I feel like this question must have been answered by someone before, but I can't find an answer on stack overflow!
我觉得这个问题以前肯定有人回答过,但是我找不到堆栈溢出的答案!
I have a dataframe result
that looks like this and I want to remove all the values less than or equal to10
我有一个result
看起来像这样的数据框,我想删除所有小于或等于10的值
>>> result
Name Value Date
189 Sall 19.0 11/14/15
191 Sam 10.0 11/14/15
192 Richard 21.0 11/14/15
193 Ingrid 4.0 11/14/15
This command works and removes all the values that are 10:
此命令有效并删除所有为 10 的值:
df2 = result[result['Value'] != 10]
But when I try to add the <= qualifier I get the error message SyntaxError: invalid syntax
但是当我尝试添加 <= 限定符时,我收到错误消息 SyntaxError: invalid syntax
df3 = result[result['Value'] ! <= 10]
I feel like there is probably a really simple solution. Thanks in advance!
我觉得可能有一个非常简单的解决方案。提前致谢!
回答by Jay Parikh
Instead of this
而不是这个
df3 = result[result['Value'] ! <= 10]
Use
用
df3 = result[~(result['Value'] <= 10)]
It will work. OR simply use
它会起作用。或者简单地使用
df3 = result[result['Value'] > 10]
回答by piRSquared
python doesn't use !
to negate. It uses not
. See this answer
In this particular example !=
is a two character string that means not equal
. It is not the negation of ==
.
python 不!
用于否定。它使用not
. 请参阅此答案
在此特定示例中!=
是一个两个字符的字符串,表示not equal
. 它不是 的否定==
。
option 1
This should work unless you have NaN
选项 1
这应该有效,除非你有NaN
result[result['Value'] > 10]
option 2
use the unary operator ~
to negate a boolean series
选项 2
使用一元运算符~
来否定布尔系列
result[~(result['Value'] <= 10)]