python - Selecting rows if at least values in one column satisfy a condition using Pandas any -
i have following data frame:
import pandas pd df = pd.dataframe({ 'gene':["foo","bar","qux","woz"], 'cell1':[5,0,1,0], 'cell2':[12,90,13,0]}) df = df[["gene","cell1","cell2"]]
which looks this:
gene cell1 cell2 0 foo 5 12 1 bar 0 90 2 qux 1 13 3 woz 0 0
what want select rows based on if @ least 1 value 2nd column onwards greater 2. yielding this:
gene cell1 cell2 0 foo 5 12 1 bar 0 90 2 qux 1 13
i tried doesn't give me want:
df[(df.values > 2).any(axis=1)]
what's right way it?
you should select cell1
, cell2
, check them against 2
. example -
in [4]: df[(df[['cell1','cell2']] > 2).any(axis=1)] out[4]: cell1 cell2 gene 0 5 12 foo 1 0 90 bar 2 1 13 qux
Comments
Post a Comment