Recall & Review
beginner
What does the & operator do in pandas when filtering data?
The & operator is used to combine multiple conditions with a logical AND, meaning both conditions must be true for the row to be selected.
Click to reveal answer
beginner
How do you combine multiple conditions with OR in pandas?
Use the | operator to combine conditions with a logical OR, so if any condition is true, the row is selected.
Click to reveal answer
intermediate
Why do you need to put each condition in parentheses when using & or | in pandas?
Parentheses ensure the correct order of operations because & and | have lower precedence than comparison operators like > or ==.
Click to reveal answer
beginner
Example: What does df[(df['age'] > 20) & (df['score'] < 50)] do?
It selects rows where the 'age' is greater than 20 AND the 'score' is less than 50.
Click to reveal answer
beginner
Can you use 'and' or 'or' instead of & and | for filtering pandas DataFrames?
No, 'and' and 'or' do not work element-wise on pandas Series. You must use & for AND and | for OR with parentheses.
Click to reveal answer
Which operator is used for element-wise AND in pandas filtering?
✗ Incorrect
In pandas, & is used for element-wise AND. 'and' is not valid for Series.
What is the correct way to filter rows where 'age' > 30 OR 'score' < 70?
✗ Incorrect
Parentheses are needed around each condition when using |. 'or' and 'and' do not work element-wise.
Why must each condition be in parentheses when using & or | in pandas?
✗ Incorrect
Parentheses ensure the comparisons happen before & or |, avoiding logic errors.
What happens if you use 'and' instead of '&' in pandas filtering?
✗ Incorrect
'and' cannot be used with pandas Series and raises a ValueError.
Which of these filters rows where 'status' is 'active' AND 'score' is above 80?
✗ Incorrect
Each condition must be in parentheses and combined with & for AND.
Explain how to filter a pandas DataFrame using multiple conditions with & and | operators.
Think about how to combine true/false checks for each row.
You got /4 concepts.
Describe why parentheses are important when using multiple conditions in pandas filtering.
Consider how Python reads expressions step-by-step.
You got /3 concepts.