Python Pandas: DataFrame filter negative values

前端 未结 4 584
独厮守ぢ
独厮守ぢ 2021-01-31 05:30

I was wondering how I can remove all indexes that containing negative values inside their column. I am using Pandas DataFrames.

Documentation Pandas DataFr

4条回答
  •  日久生厌
    2021-01-31 06:09

    If you want to check the values of an adjacent group of columns, for example from the second to the tenth:

    df[(df.ix[:,2:10] > 0).all(1)]
    

    You can also use a range

    df[(df.ix[:,range(1,10,3)] > 0).all(1)]
    

    and an own list of indices

    mylist=[1,2,4,8]
    df[(df.ix[:, mylist] > 0).all(1)]
    

提交回复
热议问题