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

Pandas condition on multiple columns

My goal is to properly select all Rows where the relevant columns (dynamically as list) meet specific conditions:

A Br
* *
None None
Test *

I can easily select the rows (dynamically) where the relevant columns are None/NaN etc with:

df[['A', 'B']].isna().all(1)

If I try the same approach with for example: * my method fails miserably:

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

df[df[['A', 'B']]=='*'].all(1)  

This return every row as True like I would expect from the ‘any’ keyword??

>Solution :

Need test boolean DataFrame:

m = (df[['A', 'B']]=='*').all(1)

Or:

m = df[['A', 'B']].eq('*').all(1)
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