DF.where multiple values

Question:

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]
Asked By: TourEiffel

||

Answers:

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"))
Answered By: INGl0R1AM0R1
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.