Filtering rows in Pandas with .loc and pd.col

Filtering rows in Pandas with .loc and pd.col

Filtering rows in a Python Pandas data frame? Use .loc:

(
  df
  .loc[ pd.col('passenger_count') > 1 ]
)

pd.col refers to the previous line’s returned data frame. So we can stack them:

(
  df
  .loc[ pd.col('passenger_count') > 1 ]
  .loc[ pd.col('total_amount') > 50 ]
)