I have a large dataframe with 30+ columns.
The first two columns ("A" and "B") contain general infromation about a feature, while the rest of columns represent different experiments for that feature.
I want to slice my dataframe to only contain rows with respective columns, in which any value was below a threshold, and furthermore include columns A and B.
My current code looks like this :
df=df.loc[df.le(0.05).any(1),].reindex(colums=["A","B"]+list(df.columns[df.le(0.05).any(0)]))
While it works, this looks very inelegant. Is there a "nicer" way to go about?
edit: Example
A | B | C | D | E |
---|---|---|---|---|
1 | 10 | 0.9 | 0.8 | 0.04 |
1 | 20 | 0.7 | 0.6 | 0.5 |
2 | 5 | 0.1 | 0.01 | 0.3 |
and as result
A | B | D | E |
---|---|---|---|
1 | 10 | 0.8 | 0.04 |
2 | 5 | 0.01 | 0.3 |