0

I am trying to execute an multiple conditional statement, If the condition passes then only further process can be executed.

I am using AND to concatenate two conditions but it gives error as ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Script that i am using so far:

if df['column1']=='Del Ind' and df['column5'].notna():
   i = pd.MultiIndex.from_product((df['state_name'],d))
   def f(x) : return Levenshtein.ratio(*x)
   out = pd.DataFrame.from_records(i,columns=['Inp','Output']).assign(Score=i.map(f))
   out = out.loc[out.groupby('Inp')['Score'].idxmax()]
  

How to correct this line of code :

if df['column1']=='Del Ind' and df['column5'].notna():

I can execute the code if i am not using the if statement, But while using under if condition it doesn't satisfy.

Please suggest how to execute.

8
  • df['column5'].notna() ur explicitly converting null to False there is issue change that or remove that party of if statement. Commented Mar 27, 2021 at 7:35
  • difficult to say what's going wrong without any data. To understand the specific error message: what should be the output of [1,2,3,4,5] > 2? Pandas is flagging the fact that the condition may have multiple (boolean) values as a response Commented Mar 27, 2021 at 7:36
  • @anon01 - The if condition is giving error while using df['column5'].notna():, What is wrong in this line . Commented Mar 27, 2021 at 7:44
  • Just before the if statement, can you add this line and say what it prints? print(df['column5']); print(df['column5'].notna()); Commented Mar 27, 2021 at 7:47
  • I have checked and it is giving as per expected, for which i have used the condition. for this df['column5'].notna() i am getting in True, False. Commented Mar 27, 2021 at 7:51

1 Answer 1

1

We need to use bitwise operations instead.

Instead of:

if df['column1']=='Del Ind' and df['column5'].notna():

Write:

if df['column1']=='Del Ind' & df['column5'].notna():
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.