Home > Software design >  How can i fix "(df[df['id']==id_value].name == 1).any()" 'The truth value o
How can i fix "(df[df['id']==id_value].name == 1).any()" 'The truth value o

Time:03-16

The following code will run fine in most cases in python(jupyter), but I'm getting an error from time to time in my web app using the following code:

 if (df[df['id']==id_value].name == 1).any():

I haven't been able to determine in which case the error occurred because it was used in web page. In what cases can the famous error below occur?

the truth value of a series is ambiguous. use a.empty a.bool() a.item() a.any() or a.all()

I've tried many cases (eg id=[1,1], name=[1,1]) but jupyter doesn't give me an error.

I have no idea what the heck is the reason.

Thank you in advance.

CodePudding user response:

Change to isin loc

 if (df.loc[df['id'].isin(id_value),'name']== 1).any():
  • Related