Home > front end >  Pandas condition on multiple columns
Pandas condition on multiple columns

Time:05-10

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:

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

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

CodePudding user response:

Need test boolean DataFrame:

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

Or:

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