mercredi 30 octobre 2019

If statement resulting in NotImplementedError: couldn't find matching opcode for 'and_bdd' followed by a VaueError

Good day, Folks.

I am trying to add a new column to a DataFrame after performing checks on the value of two other columns. The conditional statement that I have is resulting in an error that I am unable to understand and resolve.

if (DF.loc[DF['column_1']==0.0] & DF.loc[DF['column_2']==0.0]):
    DF['new_column']=1
else:
    DF['new_column']=0

The execution of code resulted in the following errors:

KeyError: ('a_value & b_value', (('optimization', 'aggressive'), ('truediv', True)), (('a_value', ), ('b_value', )))

NotImplementedError: couldn't find matching opcode for 'and_bdd'

Because I couldn't understand and resolve the above error, I decided to split the if condition as given below which resulted in a different error.

if (DF.loc[DF['column_1']==0.0]):
   if(DF.loc[DF['column_2']==0.0]):
      DF['new_column']=1
else:
    DF['new_column']=0

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

I would really appreciate if you could please help me understand what I am doing wrong here in these two scenarios.

Thanks

Aucun commentaire:

Enregistrer un commentaire