# Pandas 3.1 filter: Selecting rows with a pd.col condition

> Source: <https://lernerpython.com/2026/11/08/pandas-3-1-filter-selecting-rows-with-a-pd-col-condition/>
> Published: 2026-11-08 07:00:00+00:00

Pandas 3.1 filter: Selecting rows with a pd.col condition

November 8, 2026

Python

Python

Starting with Python Pandas 3.1, use “filter” to apply a condition to rows. So:

```
(
  df
  .loc[ pd.col('passenger_count') > 1 , 'trip_distance']
  .mean()
)
```

can now be (the much slower):

```
(
  df
  .filter(cond=pd.col('passenger_count') > 1)
  ['trip_distance']
  .mean()
)
```

←
Pandas 3.1 `select` method: Retrieving specific columns

New course: Introduction to agentic coding with Claude Code
→
