Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k points)

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

I am aware that AND corresponds to & and NOT, ~. But what about OR?

1 Answer

0 votes
by (41.4k points)

You can use this ‘ | ’ operator:

 df[(df < 12) | (df == 15)]

This will check element-wise if value is less than 12 or equal to 15.

You can also use this np.logical_or function. 

df[np.logical_or(df<3, df==5)]

For multiple conditions use the logical_or.reduce:

df[np.logical_or.reduce([df<3, df==5])]

Related questions

Browse Categories