Element-wise logical OR in Pandas

The corresponding operator is |: df[(df < 3) | (df == 5)] would elementwise check if value is less than 3 or equal to 5. If you need a function to do this, we have np.logical_or. For two conditions, you can use df[np.logical_or(df<3, df==5)] Or, for multiple conditions use the logical_or.reduce, df[np.logical_or.reduce([df<3, df==5])] Since the … Read more

Boolean operators vs Bitwise operators

Here are a couple of guidelines: Boolean operators are usually used on boolean values but bitwise operators are usually used on integer values. Boolean operators are short-circuiting but bitwise operators are not short-circuiting. The short-circuiting behaviour is useful in expressions like this: if x is not None and x.foo == 42: # … This would … Read more