query takes the condition as a string, which reads more like plain English than a mask:
df.query('region == "East" and revenue > 200')
Inside the string you write column names bare, and you can use and, or and not (no parentheses or & needed). Text values still need quotes, so wrap the whole query in single quotes and the values in double quotes, or the other way round.
- Lists:
'category in ["Lighting", "Decor"]'
- Ranges:
'100 <= revenue <= 250'
- Python variables: put
@ in front, as in 'units >= @min_units'. Without the @, pandas looks for a column with that name.
- Column names with spaces: wrap them in backticks inside the string.
query returns the matching rows like a mask does, so you can chain [["col"]], sort_values or head after it. Use whichever reads better; both are common in real code.