Keith Keith - 1 year ago 148
Python Question

Element-wise logical OR in Pandas

I would like the element-wise logical OR operator. I know "or" itself is not what I am looking for.

For AND I want to use & as explained here. For NOT I want to use np.invert() as explained here. So what is the equivalent for OR?

Answer Source

The corresponding operator is |:

 df[(df < 3) | (df == 5)]

would elementwise check if value is less than 3 or equal to 5.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download