lundi 21 janvier 2019

Python Pandas If Some of Multiple Conditions True (Boolean Math?)

So I have a data frame with 6 columns of floats (>= 0, <= 100) and I need to select every column where at least 4 of those columns are greater than 15. I could write a really, really long if statement to cover every single possibility but I feel there's a much more efficient solution. I found a similar solution in R that could solve my problem that works like this:

if(((x >= 15) + (y >= 15) + (z >= 15) + (i >= 15) + (j >= 15) + (k >= 15)) >= 4)

Does Python and/or Pandas have anything similar? It would obviously need to work in the df[(condition) & (condition)...] format as well.

Aucun commentaire:

Enregistrer un commentaire