Remove rows in python less than a certain value

后端 未结 3 663
庸人自扰
庸人自扰 2020-12-25 12:01

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

相关标签:
3条回答
  • 2020-12-25 12:13

    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 ==.

    option 1
    This should work unless you have NaN

    result[result['Value'] > 10]
    

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

    result[~(result['Value'] <= 10)]
    
    0 讨论(0)
  • 2020-12-25 12:23

    I have another suggestion, which could help

    df3 = result.drop(result[result['Value'] < 10].index, inplace = True)
    
    0 讨论(0)
  • 2020-12-25 12:30

    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]  
    
    0 讨论(0)
提交回复
热议问题