获取给定条件成立的数据帧的列号

问题描述 投票:1回答:1

我有以下代码:

raw_data = [[1, 2, 3], [4, 5, 6]]
df = pd.DataFrame(data=raw_data,
                  columns=["cA", "cB", "cC"])

wrong_indexes = df.loc[df['cA'] > 2 ]
print(wrong_indexes)

这打印:

   cA  cB  cC
1   4   5   6

而不是这个,我想只得到这个条件所持有的索引列表,如下所示:

[1]

知道我怎么能这样做吗?

python pandas dataframe
1个回答
2
投票
wrong_indexes = df.loc[df['cA'] > 2 ].index.tolist()
© www.soinside.com 2019 - 2024. All rights reserved.