0
0
Pandasdata~20 mins

Series as labeled one-dimensional array in Pandas - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Series Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of Series with custom index
What is the output of this code snippet?
Pandas
import pandas as pd
s = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
print(s['b'])
A20
B10
C30
DKeyError
Attempts:
2 left
💡 Hint
Remember that the index labels are used to access values in a Series.
data_output
intermediate
1:30remaining
Length of Series after filtering
What is the length of the Series after filtering values greater than 15?
Pandas
import pandas as pd
s = pd.Series([5, 15, 25, 35], index=['w', 'x', 'y', 'z'])
filtered = s[s > 15]
print(len(filtered))
A2
B1
C4
D3
Attempts:
2 left
💡 Hint
Count how many values are strictly greater than 15.
🔧 Debug
advanced
2:00remaining
Identify the error in Series creation
What error does this code raise?
Pandas
import pandas as pd
s = pd.Series([1, 2, 3], index=['a', 'b'])
ANo error, runs successfully
BValueError: Length of passed values is not equal to length of index
CKeyError: 'a'
DTypeError: unsupported operand type(s)
Attempts:
2 left
💡 Hint
Check if the length of the data matches the length of the index.
🚀 Application
advanced
2:00remaining
Sum values of Series with specific labels
Given this Series, what is the sum of values for labels 'b' and 'd'?
Pandas
import pandas as pd
s = pd.Series([100, 200, 300, 400], index=['a', 'b', 'c', 'd'])
result = s[['b', 'd']].sum()
print(result)
A700
B500
C600
DKeyError
Attempts:
2 left
💡 Hint
Add the values corresponding to labels 'b' and 'd'.
🧠 Conceptual
expert
2:30remaining
Effect of duplicate labels in Series
What happens when you create a Series with duplicate index labels and then select by that label?
Pandas
import pandas as pd
s = pd.Series([1, 2, 3, 4], index=['a', 'b', 'b', 'c'])
result = s['b']
print(result)
ARaises a KeyError because of duplicate labels
BReturns the first value for label 'b': 2
CReturns the last value for label 'b': 3
DReturns a Series with all values for label 'b': [2, 3]
Attempts:
2 left
💡 Hint
Think about how pandas handles duplicate index labels when selecting.