6
Python Pandas:获取列匹配特定值的行的索引
给定一个带有“ BoolCol”列的DataFrame,我们要查找其中“ BoolCol” == True的值的DataFrame索引 我目前有迭代的方式来做,很完美: for i in range(100,3000): if df.iloc[i]['BoolCol']== True: print i,df.iloc[i]['BoolCol'] 但这不是正确的熊猫方法。经过研究,我目前正在使用以下代码: df[df['BoolCol'] == True].index.tolist() 这给了我一份索引列表,但是当我通过以下方法检查它们时,它们不匹配: df.iloc[i]['BoolCol'] 结果实际上是错误的! 哪一种是正确的Pandas方法?