Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DF.where multiple values

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Doing :

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

returns :

TypeError: Cannot perform 'rand_' with a dtyped [object] array and scalar of type [bool]

>Solution :

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"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading