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]
CodePudding user response:
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"))