0

Doing the following :

DF.where(DF['Test']=="a" and DF['Test']=="b")

throw the error :

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

What am I doing wrong ?

Doing :

 DF.where(DF['Test']=="a" & DF['Test']=="b")

returns :

TypeError: Cannot perform 'rand_' with a dtyped [object] array and scalar of type [bool]
TourEiffel
  • 4,034
  • 2
  • 16
  • 45

1 Answers1

1

In this case or condition doesn't make a lot of sense, either you want the events of A OR B, never A and B (unless it is a string column). And you are filtering it. In your case I think all you should do is maybe make a isin.

Like the sample

df.where[df['test'].isin(['A','B'])

Also there is an error in your filter case. You are using Python logical constructor when Pandas logical constructor are & | and ~ like this question show peta

Also, there is a bracket issue :

 DF.where((DF['Test']=="a") & (DF['Test']=="b"))
TourEiffel
  • 4,034
  • 2
  • 16
  • 45
INGl0R1AM0R1
  • 1,532
  • 5
  • 16
  • Hi, upvoted you workaround and also edited your answer by highlighting my mistake. Many thanks, and will accept your answer as soon as i can ! – TourEiffel Sep 19 '22 at 13:44