0

I am trying to define a new column in pandas if one of the other three string columns are specific values.

df.loc[df['member1_labels'] == 'F' or df['member2_labels'] == 'F' or df['member3_labels'] == 'F', 'total_score'] = 'F'

But 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().

How I can fix this?

mozway
  • 194,879
  • 13
  • 39
  • 75
Paul
  • 59
  • 5
  • 1
    Hey Paul, I think all you need to do is encase those conditions in parentheses, like `df.loc[(cond1) or (cond2) or (cond3), 'your_col']` – Onur Guven Apr 12 '22 at 11:06
  • Thanks for your response. I just did it, but it does not work. The same error is showing up. – Paul Apr 12 '22 at 11:15
  • 2
    @Onur `or` is not valid for vectors, one should use `|` instead (and the parentheses!) – mozway Apr 12 '22 at 11:15

0 Answers0