Challenge - 5 Problems
Boolean Filtering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Boolean filtering with pandas
What is the output of this code snippet filtering a DataFrame by a Boolean condition?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [5, 6, 7, 8]}) filtered = df[df['A'] > 2] print(filtered)
Attempts:
2 left
💡 Hint
Remember that filtering keeps rows where the condition is True.
✗ Incorrect
The condition df['A'] > 2 is True for rows where A is 3 or 4, so only those rows remain.
❓ data_output
intermediate1:30remaining
Count of rows after Boolean filtering
After applying this Boolean filter, how many rows remain in the DataFrame?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'score': [55, 70, 65, 80, 90]}) filtered = df[df['score'] >= 70] print(len(filtered))
Attempts:
2 left
💡 Hint
Count how many scores are 70 or above.
✗ Incorrect
Scores 70, 80, and 90 meet the condition, so 3 rows remain.
🔧 Debug
advanced2:00remaining
Identify the error in Boolean filtering code
What error does this code raise when trying to filter a DataFrame?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'X': [10, 20, 30]}) filtered = df[df['X' > 15]] print(filtered)
Attempts:
2 left
💡 Hint
Look carefully at the condition inside the brackets.
✗ Incorrect
The expression 'X' > 15 compares a string to an integer, which is invalid and raises a TypeError.
🚀 Application
advanced2:30remaining
Filter DataFrame rows with multiple Boolean conditions
Which option correctly filters rows where column 'age' is over 30 and 'income' is at least 50000?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'age': [25, 35, 40, 28], 'income': [40000, 60000, 50000, 45000]})
Attempts:
2 left
💡 Hint
Use bitwise operators (&, |) for combining conditions in pandas.
✗ Incorrect
In pandas, use & for AND and | for OR with conditions inside parentheses.
🧠 Conceptual
expert3:00remaining
Understanding Boolean indexing with missing values
Given a DataFrame with missing values, what does this Boolean filter return?
Data Analysis Python
import pandas as pd import numpy as np df = pd.DataFrame({'val': [1, np.nan, 3, np.nan, 5]}) filtered = df[df['val'] > 2] print(filtered)
Attempts:
2 left
💡 Hint
NaN compared with any number returns False in Boolean filtering.
✗ Incorrect
NaN values do not satisfy the condition and are excluded from the filtered result.