Challenge - 5 Problems
Series Sorting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of sorting a Series with missing values?
Consider the following pandas Series with some missing values. What will be the output after sorting it in ascending order?
Data Analysis Python
import pandas as pd s = pd.Series([3, None, 1, 2, None]) s_sorted = s.sort_values() print(s_sorted)
Attempts:
2 left
💡 Hint
Remember that pandas places NaN values at the end by default when sorting ascending.
✗ Incorrect
When sorting a Series with missing values (NaN), pandas sorts the non-NaN values in ascending order and places NaNs at the end by default. The original indices are preserved in the sorted output.
❓ data_output
intermediate1:30remaining
How many items are in the sorted Series after dropping duplicates?
Given the Series below, after sorting it in descending order and dropping duplicates, how many items remain?
Data Analysis Python
import pandas as pd s = pd.Series([5, 3, 5, 2, 3, 1]) s_sorted_unique = s.sort_values(ascending=False).drop_duplicates() print(len(s_sorted_unique))
Attempts:
2 left
💡 Hint
Count unique values after sorting descending.
✗ Incorrect
The unique values in the Series are 5, 3, 2, 1. After sorting descending and dropping duplicates, 4 items remain.
🔧 Debug
advanced2:00remaining
What error does this sorting code raise?
Examine the code below. What error will it raise when executed?
Data Analysis Python
import pandas as pd s = pd.Series(['a', 'b', 3, 'd']) s_sorted = s.sort_values() print(s_sorted)
Attempts:
2 left
💡 Hint
Think about comparing strings and integers during sorting.
✗ Incorrect
Sorting a Series with mixed types like strings and integers raises a TypeError because Python cannot compare these types directly.
❓ visualization
advanced2:30remaining
Which plot shows the Series sorted in ascending order?
You have this Series: s = pd.Series([4, 1, 3, 2]). Which plot correctly shows the Series after sorting it in ascending order?
Data Analysis Python
import pandas as pd import matplotlib.pyplot as plt s = pd.Series([4, 1, 3, 2]) s_sorted = s.sort_values() s_sorted.plot(kind='bar') plt.show()
Attempts:
2 left
💡 Hint
Sorting ascending means smallest value first on the left.
✗ Incorrect
Sorting the Series in ascending order arranges values as 1, 2, 3, 4. The bar plot shows bars in this order from left to right.
🧠 Conceptual
expert1:30remaining
What is the effect of the 'inplace=True' parameter in Series.sort_values()?
When you use s.sort_values(inplace=True) on a pandas Series s, what happens?
Attempts:
2 left
💡 Hint
Think about whether the original data changes or a new object is created.
✗ Incorrect
Using inplace=True sorts the Series in place, modifying the original Series and returning None.