Filtering Rows with the Query Function

Learn how to use the query function for filtering a DataFrame.

We'll cover the following

The query function

The query function is another way to filter values in a DataFrame.

It differs from previous functions because it can write the conditions as text. It’s quite useful and is more practical in various cases.

Here’s how we can select products with a price higher than 100 by using the query function:

sales_filtered = sales.query("price > 100")

We can apply multiple conditions with the query function as well.

In the previous lesson, we created a condition based on the price and stock quantity columns. Let’s do the same using the query function.

Get hands-on with 1400+ tech skills courses.