Next →

What is Filtering?

Filtering lets you select rows in a DataFrame that meet specific conditions — like finding all sales over $1,000 or customers from London.

How to Filter Rows

Use boolean indexing to filter a DataFrame:

df[df["column_name"] condition]

For example, to filter all sales greater than 1000:

df[df["sales"] > 1000]

You can also filter using multiple conditions with & (and) or | (or). Example:

df[(df["sales"] > 1000) & (df["region"] == "West")]

Don’t forget to wrap conditions in parentheses!

Storing the Filtered Data

You can store filtered results in a new variable:

high_sales = df[df["sales"] > 1000]
print(high_sales)