0
0
Pandasdata~30 mins

Boolean indexing in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Boolean Indexing with pandas
📖 Scenario: You work in a small store and have a list of products with their prices. You want to find which products cost more than $20 to decide what to promote.
🎯 Goal: Use boolean indexing in pandas to filter products that cost more than $20.
📋 What You'll Learn
Create a pandas DataFrame with product names and prices
Create a boolean condition to select products with price greater than 20
Use boolean indexing to filter the DataFrame
Print the filtered DataFrame
💡 Why This Matters
🌍 Real World
Stores often need to filter products by price to create promotions or discounts.
💼 Career
Data analysts use boolean indexing in pandas to quickly filter and analyze data based on conditions.
Progress0 / 4 steps
1
Create the products DataFrame
Import pandas as pd and create a DataFrame called products with these exact entries: product names 'Pen', 'Notebook', 'Eraser', 'Backpack', and prices 5, 25, 3, 45 respectively.
Pandas
Need a hint?

Use pd.DataFrame with a dictionary containing keys 'product' and 'price'.

2
Create a boolean condition for prices over 20
Create a variable called expensive that holds a boolean Series selecting rows from products where the price is greater than 20.
Pandas
Need a hint?

Use products['price'] > 20 to create the boolean Series.

3
Filter products using boolean indexing
Create a new DataFrame called expensive_products by using boolean indexing on products with the expensive variable.
Pandas
Need a hint?

Use products[expensive] to filter the rows.

4
Print the filtered DataFrame
Print the expensive_products DataFrame to show only products with price greater than 20.
Pandas
Need a hint?

Use print(expensive_products) to display the filtered DataFrame.