Challenge - 5 Problems
Boolean Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Boolean Indexing on DataFrame
What is the output of this code snippet using Boolean indexing on a DataFrame?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'Name': ['Anna', 'Bob', 'Cara', 'Dave'], 'Age': [23, 35, 22, 40], 'Score': [88, 92, 85, 95] }) result = df[df['Age'] > 30] print(result)
Attempts:
2 left
💡 Hint
Look for rows where Age is greater than 30.
✗ Incorrect
Boolean indexing filters rows where the condition is True. Here, only Bob and Dave have Age > 30.
❓ data_output
intermediate1:30remaining
Count of Rows After Boolean Indexing
How many rows remain after applying this Boolean indexing?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'City': ['NY', 'LA', 'NY', 'SF', 'LA'], 'Temperature': [75, 85, 70, 65, 90] }) filtered = df[df['City'] == 'LA'] print(len(filtered))
Attempts:
2 left
💡 Hint
Count how many times 'LA' appears in the City column.
✗ Incorrect
There are exactly two rows where City is 'LA'.
🔧 Debug
advanced2:00remaining
Identify the Error in Boolean Indexing
What error does this code raise when trying to filter a DataFrame?
Data Analysis Python
import pandas as pd df = pd.DataFrame({ 'Product': ['A', 'B', 'C'], 'Price': [100, 200, 300] }) filtered = df[df.Price > 150] filtered = df[df['Price' > 150]] print(filtered)
Attempts:
2 left
💡 Hint
Look carefully at the second filtering line syntax.
✗ Incorrect
The second line evaluates 'Price' > 150, which compares a string to an int, raising TypeError: '>' not supported between instances of 'str' and 'int'.
❓ visualization
advanced2:30remaining
Visualize Filtered Data Using Boolean Indexing
Which option shows the correct plot of scores for students older than 20?
Data Analysis Python
import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({ 'Student': ['Tom', 'Lucy', 'John', 'Anna'], 'Age': [19, 22, 21, 18], 'Score': [88, 95, 90, 85] }) filtered = df[df['Age'] > 20] plt.bar(filtered['Student'], filtered['Score']) plt.show()
Attempts:
2 left
💡 Hint
Check which students have Age > 20.
✗ Incorrect
Only Lucy and John have Age greater than 20, so only their scores appear in the bar chart.
🧠 Conceptual
expert3:00remaining
Effect of Boolean Indexing on DataFrame Copy vs View
After applying Boolean indexing on a DataFrame, what is true about the resulting DataFrame?
Attempts:
2 left
💡 Hint
Think about how pandas handles filtering and memory.
✗ Incorrect
Boolean indexing sometimes returns a copy and sometimes a view; this depends on pandas internals and can affect whether changes propagate.