Given a DataFrame with a column “BoolCol”, we want to find the indexes of the DataFrame in which the values for “BoolCol” == True

I currently have the iterating way to do it, which works perfectly:

for i in range(100,3000):
    if df.iloc[i]['BoolCol']== True:
         print i,df.iloc[i]['BoolCol']

But this is not the correct panda’s way to do it.
After some research, I am currently using this code:

df[df['BoolCol'] == True].index.tolist()

This one gives me a list of indexes, but they dont match, when I check them by doing:

df.iloc[i]['BoolCol']

The result is actually False!!

Which would be the correct Pandas way to do this?

7 Answers
7

Leave a Reply

Your email address will not be published. Required fields are marked *