Recall & Review
beginner
What is Boolean indexing in pandas?
Boolean indexing is a way to select rows or columns in a DataFrame using a condition that returns True or False for each element. It filters data based on these True/False values.
Click to reveal answer
beginner
How do you create a Boolean mask to select rows where a column 'age' is greater than 30?
You write: df['age'] > 30. This creates a Series of True/False values for each row, True if age is greater than 30, else False.
Click to reveal answer
beginner
How do you apply a Boolean mask to a DataFrame to get filtered rows?
Use the mask inside square brackets: df[df['age'] > 30]. This returns only rows where the condition is True.
Click to reveal answer
intermediate
Can Boolean indexing be combined with multiple conditions? How?
Yes. Use & for AND, | for OR, and wrap each condition in parentheses. Example: df[(df['age'] > 30) & (df['city'] == 'NY')]
Click to reveal answer
beginner
What happens if you use Boolean indexing with a condition that has no True values?
The result is an empty DataFrame with the same columns but no rows, because no rows meet the condition.
Click to reveal answer
What does df[df['score'] > 50] return?
✗ Incorrect
The condition df['score'] > 50 creates a Boolean mask selecting rows where 'score' is greater than 50.
Which operator is used for AND in multiple Boolean conditions in pandas?
✗ Incorrect
In pandas, & is used for element-wise AND between Boolean Series. Conditions must be wrapped in parentheses.
What type of object does a Boolean condition like df['age'] > 25 return?
✗ Incorrect
The condition returns a Series of True/False values, one for each row.
What will df[df['name'] == 'Alice'] return if no rows have name 'Alice'?
✗ Incorrect
If no rows match the condition, the result is an empty DataFrame with the same columns.
How do you select rows where 'age' is greater than 20 OR 'city' is 'LA'?
✗ Incorrect
Use | for OR between conditions, each wrapped in parentheses.
Explain how Boolean indexing works in pandas and give a simple example.
Think about how you pick items from a list using True/False values.
You got /4 concepts.
Describe how to combine multiple conditions in Boolean indexing and why parentheses are important.
Remember operator precedence and how Python evaluates expressions.
You got /4 concepts.