我有以下称为df的数据框。
x1 x2 x3 ....
row1 12 3.4 5 ...
row2 1 3 4 ...
row3 True False True ...
...
我想显示所有row3值都为True的列。
因此像列x1
,x3
将在此示例中显示。
当我想根据列信息过滤行时,我知道怎么做,但是当我想根据行过滤时,我不确定如何做。
我试过了
df.loc[:,df.iloc['row3']==True]
但我得到一个错误。
我该怎么做呢?有任何想法吗?
iloc
要求您传递整数(列表)。尝试loc
:
df.loc[:,df.loc['row3']]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句