samedi 27 mai 2017

Pandas Throwing Error in Loop Using If/Then/Else Statement

I have a strange error occurring that I can't figure out.

Hoping for some help.

I have an if statement in my code as follows:

if my_df.ix[my_df['SOMEINTEGER'] == another_df.ix[i,'SOMECOMPARABLEINTEGER'],'SOMECOLUMN'] == 'I':

    *** DO SOMETHING ***
    i+=1

What this statement does is choose the row in my_df where 'SOMEINTEGER' equals the integer value in another_df.ix[i,'SOMECOMPARABLEINTEGER'] and check to see if the column value in 'SOMECOLUMN' in my_df is equal to 'I'

If I run the if statement as a single line of code with the value i set to an integer corresponding to a dataframe index value it works.

If I include this if statment in a larger iteration (and similiarly move the incrementing i out so it increments properly I get the following error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

I'm unable to isolate the source of the error.

Any help/insight appreciated.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire