Filtering lets you select rows in a DataFrame that meet specific conditions — like finding all sales over $1,000 or customers from London.
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!
You can store filtered results in a new variable:
high_sales = df[df["sales"] > 1000]
print(high_sales)