Delete lines in python less than a certain value

It seems to me that someone had to answer this question before, but I can not find the answer to the stack overflow!

I have a dataframe result that looks like this and I want to remove all values ​​that are less than or equal to 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 values ​​equal to 10:

 df2 = result[result['Value'] != 10] 

But when I try to add the <= qualifier, I get the SyntaxError: invalid syntax error

 df3 = result[result['Value'] ! <= 10] 

I feel that there is probably a very simple solution. Thanks in advance!

+5
source share
2 answers

Instead of this

 df3 = result[result['Value'] ! <= 10] 

Using

 df3 = result[~(result['Value'] <= 10)] 

It will work. OR just use

 df3 = result[result['Value'] > 10] 
+6
source

python does not use ! to cancel. He uses not . See this answer
In this particular example != Is a two-character string that means not equal . This is not a denial == .

option 1
This should work if you do not have NaN

 result[result['Value'] > 10] 

option 2
use the unary operator ~ to negate the boolean series

 result[~(result['Value'] <= 10)] 
+5
source

Source: https://habr.com/ru/post/1263185/


All Articles