Home > Software engineering >  Python pandas - ambiguous conditions
Python pandas - ambiguous conditions

Time:01-11

Why are these conditions ambiguous, please?

selected_F = selected.loc[ ((selected['L_ratio_5au'] > 0.1) & 
                  (selected['L_ratio_5au'] < 1)) or
                  ((selected['L_ratio'] > 0.1) & 
                  (selected['L_ratio'] < 1)) ]

I meant that at least one of the two columns 'L_ratio_5au' and 'L_ratio' has to be between the 0.1 and 1.0.

Thank you

CodePudding user response:

You have to use | (bitwise operator) instead of or (logical operator). You could also use between to simplify your expression:

selected_F = selected.loc[selected['L_ratio_5au'].between(0.1, 1, include='neither')
                          | selected['L_ratio'].between(0.1, 1, include='neither')]
  • Related