0
0
Data Analysis Pythondata~30 mins

Boolean indexing in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Boolean Indexing
📖 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 on a pandas DataFrame to select products with prices greater than $20.
📋 What You'll Learn
Create a pandas DataFrame with product names and prices
Create a boolean condition to select products priced above $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 to quickly select data subsets for reports and decision-making.
Progress0 / 4 steps
1
Create the products DataFrame
Import pandas as pd and create a DataFrame called products with these exact entries: 'Product' column with values 'Pen', 'Notebook', 'Backpack', 'Calculator', and 'Water Bottle', and 'Price' column with values 5, 15, 45, 30, and 10 respectively.
Data Analysis Python
Need a hint?

Use pd.DataFrame with a dictionary containing two lists for columns.

2
Create a boolean condition for prices above 20
Create a variable called expensive that stores a boolean Series by checking which products['Price'] values are greater than 20.
Data Analysis Python
Need a hint?

Use the comparison operator > on the Price column.

3
Filter products using boolean indexing
Create a new DataFrame called expensive_products by selecting rows from products where expensive is True using boolean indexing.
Data Analysis Python
Need a hint?

Use products[expensive] to filter rows.

4
Print the filtered DataFrame
Print the expensive_products DataFrame to see the products with prices greater than $20.
Data Analysis Python
Need a hint?

Use print(expensive_products) to display the filtered DataFrame.