Pandas loc filter order: Put the most selective filter first

Pandas loc filter order: Put the most selective filter first

Stacking loc to filter a Python Pandas dataframe? Order can matter:

(
  df
  .loc[ pd.col('total_amount') > 25 ]
  .loc[ pd.col('passenger_count') > 0 ]
) # 64.5 ms
(
  df
  .loc[ pd.col('passenger_count') > 0 ]
  .loc[ pd.col('total_amount') > 25 ]
) # 95.8 ms -- 48% slower