获取包含特定值熊猫的列的索引

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

我想找到包含特定值的列的索引。我有大数据集(超过2500列),值可以位于任何列中。

所以,我不知道该值所在的列的名称。数据集很大,超过2500列,值可以是2500列中的任何一个。

这仅是示例数据集:

import pandas as pd

#THIS IS THE EXAMPLE ONLY, DATASET IS VERY BIG 
df = pd.DataFrame({'one':[1,2,3,4,5],
                   'two':[45,4,3,2,4],
                   'three':[4,2,111,3,5]})
print(df)

i = df[df==111].index
print(i)
#RESULT SHOULD BE INDEX 2
python pandas
1个回答
0
投票

您需要将any的轴设置为any,并用结果索引数据框:

1
© www.soinside.com 2019 - 2024. All rights reserved.