Skip to content
Advertisement

select pandas rows based on 2 conditions using or

I have a pandas dataframe filled with values between 0 and 3 and now I would like to either select the max value and return the column label or return ‘undecided’ if a row does only contain 0 and 1 across multiple columns.

so far I have the first part sorted:

JavaScript

How do I write the second part?

My dataframe looks like this and I want to add a column ‘result’ to it:

JavaScript

Advertisement

Answer

Use mask to hide rows that do not respect the constraint:

JavaScript

Output of mask:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement