0
0
Pandasdata~30 mins

Selecting rows by condition in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Selecting rows by condition
📖 Scenario: You work in a small bookstore. You have a list of books with their prices and want to find which books cost more than $20.
🎯 Goal: Build a program that selects and shows only the books priced above $20 from the list.
📋 What You'll Learn
Create a pandas DataFrame with book titles and prices
Create a variable to hold the price threshold
Use a condition to select rows where price is greater than the threshold
Print the filtered DataFrame
💡 Why This Matters
🌍 Real World
Filtering data by conditions is common in business to find important items, like expensive products or customers with high spending.
💼 Career
Data analysts and scientists often filter datasets to focus on relevant information for reports and decisions.
Progress0 / 4 steps
1
Create the books DataFrame
Import pandas as pd. Create a DataFrame called books with these exact entries: titles 'Book A', 'Book B', 'Book C', and prices 15, 25, 30 respectively.
Pandas
Need a hint?

Use pd.DataFrame with a dictionary containing lists for titles and prices.

2
Set the price threshold
Create a variable called price_threshold and set it to 20.
Pandas
Need a hint?

Just assign the number 20 to the variable price_threshold.

3
Select books priced above the threshold
Create a new DataFrame called expensive_books by selecting rows from books where the price column is greater than price_threshold.
Pandas
Need a hint?

Use books[books['price'] > price_threshold] to filter rows.

4
Print the filtered books
Print the expensive_books DataFrame to show the books priced above $20.
Pandas
Need a hint?

Use print(expensive_books) to display the filtered DataFrame.