【发布时间】:2021-02-24 19:30:05
【问题描述】:
这是对我之前的问题的扩展。
Filter pandas columns based on row condition
现在我想有多个条件来过滤列。
这是我的数据
x1 x2 x3 ....
row1 12 3.4 5 ...
row2 1 3 4 ...
row3 True False True ...
...
如果我只想过滤True 的row3 条件,df.loc[[:,df.loc['row3']==True] 可以工作
我想过滤row3 为true 的列,
and 我想过滤row2 为>3 的列
所以在这个例子中只有 x3 列应该出现。
我尝试了以下代码,但出现错误。我也尝试添加括号。
df.loc[:,df.loc['row3']==True & :,df.loc['row2']>3]
有什么想法吗?
【问题讨论】: