Search code examples
pythonpandasany

Pandas any/all doesn't seem to return right results


I have the following dataframe:

test = 

    fa_count    dist_fa_count   dsc_count   dist_dsc_count
       0    63403.285714         1.0          1.0   1.0
       1    37837.285714         1.0          1.0   1.0
       2    9185.285714          1.0          1.0   1.0
       3    23729.142857         1.0          1.0   1.0
       4    22288.142857         1.0          1.0   1.0
       5    77365.000000         1.0          1.0   1.0

I want to return any index + row that has a value != 1 (i.e. every row in this case).

 test.all(1) == 1

returns all true and

test.any(1) != 1 

returns all false. Any idea why/another way?


Solution

  • You want something like

    (test == 1).all(1) 
    

    and

    (test != 1).any(1)