The query() Method for Readable Filters
For complex filters, query() lets you write conditions as strings - often more readable than bracket notation.
df.query('age > 30 and status == "active"')
No need for df['column'] syntax or parentheses. Just write conditions naturally.
You can use variables with @:
min_age = 25
df.query('age >= @min_age')
Spaces in column names work with backticks:
df.query('`user name` == "Alice"')
The query() method is especially nice for interactive exploration and when sharing code with non-programmers who can read the logic easily.
For more query patterns, see The Ultimate Pandas Bootcamp.