In this exercise, you will learn to filter data based on multiple conditions simultaneously. This helps in narrowing down specific customer segments efficiently.
Filter Customers Aged Between 20 and 40:
Use the & operator to combine two conditions.
Print the first few rows of the filtered data using head().
Filter Customers Older Than 30 and Spending Over $90:
Combine the conditions using & for both age and purchase amount.
Print the first few rows of the result.
Python Code:
#1.Filter Customers Aged Between 20 and 40:
import pandas as pd
age_filtered = df[(df['Age'] >= 20) & (df['Age'] <= 40)]
age_filtered.head()
# 2. Filter rows where 'Age' > 30 and 'Purchase Amount (USD)' > 100
import pandas as pd
combined_conditions = df[(df['Age'] > 30) & (df['Purchase Amount (USD)'] > 90)]
combined_conditions.head()