Challenge - 5 Problems
DataFrame Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this DataFrame selection?
Given the DataFrame below, what will be the output of
df.loc['b', 'Y']?Pandas
import pandas as pd df = pd.DataFrame({ 'X': [10, 20, 30], 'Y': [40, 50, 60], 'Z': [70, 80, 90] }, index=['a', 'b', 'c']) result = df.loc['b', 'Y'] print(result)
Attempts:
2 left
💡 Hint
Remember that
loc selects by label for both rows and columns.✗ Incorrect
The row labeled 'b' has values X=20, Y=50, Z=80. Selecting column 'Y' gives 50.
❓ data_output
intermediate1:30remaining
How many rows and columns does this DataFrame have?
Consider the DataFrame created below. What is the shape (rows, columns) of
df?Pandas
import pandas as pd df = pd.DataFrame({ 'A': range(5), 'B': range(5, 10), 'C': range(10, 15) }) print(df.shape)
Attempts:
2 left
💡 Hint
Shape returns (number of rows, number of columns).
✗ Incorrect
The DataFrame has 5 rows (0 to 4) and 3 columns (A, B, C).
🔧 Debug
advanced1:30remaining
What error does this code raise?
What error will this code produce when run?
Pandas
import pandas as pd df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) value = df.loc[2, 'col1'] print(value)
Attempts:
2 left
💡 Hint
Check if the row label 2 exists in the DataFrame index.
✗ Incorrect
The DataFrame index is [0,1]. Accessing label 2 with loc causes a KeyError.
❓ visualization
advanced2:00remaining
Which plot shows the correct bar chart of column sums?
Given the DataFrame below, which option shows the correct bar chart of the sum of each column?
Pandas
import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({ 'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9] }) col_sums = df.sum() plt.bar(col_sums.index, col_sums.values) plt.show()
Attempts:
2 left
💡 Hint
Sum each column and plot those sums as bar heights.
✗ Incorrect
Sum of A is 6 (1+2+3), B is 15 (4+5+6), C is 24 (7+8+9). The bar chart should reflect these values.
🚀 Application
expert2:30remaining
What is the value of 'result' after filtering and grouping?
Given the DataFrame below, what is the value of
result after filtering rows where 'score' > 70 and grouping by 'team' to get the mean 'score'?Pandas
import pandas as pd df = pd.DataFrame({ 'team': ['A', 'B', 'A', 'B', 'C'], 'score': [65, 85, 75, 90, 60] }) filtered = df[df['score'] > 70] result = filtered.groupby('team')['score'].mean() print(result)
Attempts:
2 left
💡 Hint
Filter first, then group by team and calculate mean score.
✗ Incorrect
Filtered rows have scores > 70: A=75, B=85 and 90. Mean for A is 75, for B is (85+90)/2=87.5.