IconResources
Conduct analysis

Filter

View only the rows that match a specific condition without modifying the dataset.

Example Data

Follow along with right out of the box example data. Copy following data in the information request of the agent you are working in.



Filtering helps you focus on relevant data. Whether you're reviewing transactions above a certain amount, or isolating rows by country or product type, filtering lets you view only the rows that matter — without deleting anything. It's like using sunglasses to block glare: the full dataset is still there, but you're seeing only what you need.

In this section, we’ll learn how to filter a dataset in Python the same way you would in Excel — based on values, text, or logic.

Filter rows by numeric condition

Excel

In Excel, you use filters or formulas like >10000000 to show only large values.

t0 Prompt

Show only transactions above 10 million

Filter rows where amount is more than 8 million

Display only high-value rows

Code

The python code looks as follows:

transactions["Amount"] = pd.to_numeric(transactions["Amount"])
transactions[transactions["Amount"] > 10_000_000]

Filter rows by text condition

Excel

In Excel, you click the dropdown arrow and select a country, name, or keyword to filter.

t0 Prompt

Filter rows where the seller is in Italy

Show only transactions with Sweden as buyer

Display services only

Code

The python code looks as follows:

transactions[transactions["Buyer Country"] == "Sweden"]

Filter using multiple conditions

Excel

In Excel, you can apply filters to multiple columns, or use advanced filter formulas.

t0 Prompt

Show only rows where amount > 10 million and country is Brazil

Filter by column X and Y at the same time

Apply multiple conditions: X, Y, and Z

Code

The python code looks as follows:

transactions["Amount"] = pd.to_numeric(transactions["Amount"])
filtered = transactions[
    (transactions["Amount"] > 10_000_000) &
    (transactions["Buyer Country"] == "Brazil")
]
filtered
FunctionDescription
df[condition]Filters rows based on a condition
==, !=, <, >, >=, <=Standard comparison operators

On this page