1

I'm trying to create a loc dataframe with multiple conditional statements. The problem I am having is that when I use and 'and' operator for my second conditional statement, I get the error below.

As a side problem, is there any better way to seperate the conditional statements than with |.

My code:

df = df2.loc[(df2['Position'] == 0) | (df2['TABNo'] == 0 and df2['IsBarrierTrial'] == 'FALSE')]

Error with and operator:

The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
2
  • What is the problem with the operator |? Commented Aug 18, 2022 at 14:05
  • Nothing just not neat Commented Aug 18, 2022 at 14:14

1 Answer 1

1

Make sure they are correctly separated by parenthesis to group the logics and consider using bitwise operator:

df = df2.loc[(df2['Position'] == 0) | ((df2['TABNo'] == 0) & (df2['IsBarrierTrial'] == 'FALSE'))]
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.