Challenge - 5 Problems
Ranking Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Ranking Chart Code
What will be the output of this code snippet that creates a ranking chart using matplotlib?
Matplotlib
import matplotlib.pyplot as plt import pandas as pd scores = {'Alice': 88, 'Bob': 95, 'Charlie': 70, 'David': 85} ranked = pd.Series(scores).rank(ascending=False, method='min') plt.bar(ranked.index, ranked.values) plt.gca().invert_yaxis() plt.title('Ranking Chart') plt.ylabel('Rank') plt.show()
Attempts:
2 left
💡 Hint
Look at how rank is calculated and how y-axis is inverted.
✗ Incorrect
The code ranks scores descending, then plots ranks as bars with names on x-axis. Inverting y-axis puts rank 1 at top.
❓ data_output
intermediate1:30remaining
Number of Items in Ranked Data
Given this code that ranks data, how many items are in the resulting ranked Series?
Matplotlib
import pandas as pd scores = {'Anna': 78, 'Ben': 82, 'Cara': 78, 'Derek': 90} ranked = pd.Series(scores).rank(ascending=False, method='min')
Attempts:
2 left
💡 Hint
Count the keys in the original dictionary.
✗ Incorrect
The ranked Series has one rank per original item, so it has 4 items.
❓ visualization
advanced2:30remaining
Identify the Correct Ranking Chart Visualization
Which option shows the correct matplotlib code to create a horizontal ranking bar chart with names on y-axis and ranks on x-axis, with rank 1 at left?
Attempts:
2 left
💡 Hint
Horizontal bar charts use barh; invert x-axis to put rank 1 at left.
✗ Incorrect
Option D correctly uses barh with names on y-axis and ranks on x-axis, then inverts x-axis to have rank 1 on left.
🔧 Debug
advanced2:00remaining
Error in Ranking Chart Code
What error will this code produce when run?
Matplotlib
import matplotlib.pyplot as plt import pandas as pd scores = {'Eve': 92, 'Frank': 85} ranked = pd.Series(scores).rank(ascending=False) plt.bar(ranked.values, ranked.index) plt.show()
Attempts:
2 left
💡 Hint
Check the order of arguments in plt.bar(x, height).
✗ Incorrect
plt.bar expects x as categories and height as numeric values. Here, x and height are reversed causing size mismatch error.
🚀 Application
expert3:00remaining
Create a Ranking Chart with Ties Correctly Displayed
You have scores with ties: {'Gina': 88, 'Hank': 88, 'Ivy': 75}. Which code correctly creates a ranking chart that assigns the same rank to ties and plots them with rank 1 at top?
Attempts:
2 left
💡 Hint
Use method='min' to assign the same lowest rank to ties and invert y-axis for rank 1 at top.
✗ Incorrect
Method 'min' assigns the lowest rank to tied scores. Ascending=False ranks highest score as 1. Inverting y-axis puts rank 1 at top.