Filtering by Condition
Learn how to filter values in a DataFrame based on a condition or a set of conditions.
We'll cover the following...
How to filter a DataFrame
by condition
Recall the sales
we’ve been using. It contains products that belong to one of six different product groups. Suppose we’re interested in only one product group and would like to filter products that belong to this group.
The following line of code selects the products that belong to product group PG2
. Remember that each row in the sales represents a product.
sales_filtered = sales[sales.product_group == "PG2"]
The ...
Access this course and 1400+ top-rated courses and projects.