Pandas OR conditions: Filtering rows with | and parentheses

Pandas OR conditions: Filtering rows with | and parentheses

Want rows in a Python Pandas data frame that might have several values? You can use the | operator, but be sure to use () to avoid precedence issues:

(
  df
  .loc[((pd.col('passenger_count') == 5) |
        (pd.col('passenger_count') == 7))]
)