Completed
Mixed: Series revision
Questions From This Challenge
Q1mcq1 mark
A Series is created from the dictionary {'a': 10, 'b': 20, 'c': 30}, and another Series s2 = pd.Series([1, 2, 3], index=['a', 'b', 'c']) is added to it. What determines the resulting index labels?
The set of index labels common to (or present in) both Series, aligned by label ✓
The order in which the dictionary keys were typed, ignoring s2 entirely
Only the index of s2
A fresh default RangeIndex
Q2mcq1 mark
A Series is created from a NumPy ndarray with 6 elements and a custom index. Calling .tail(2) on it returns:
The last 2 elements with their corresponding custom index labels ✓
The first 2 elements with their corresponding custom index labels
The last 2 elements with a fresh default integer index
An error, since custom indices don't support tail()
Q3mcq1 mark
A Series is created as pd.Series(7, index=['m', 'n', 'o']). What is the value of s['n']?
7 ✓
'n'
0
An error, since scalar-created Series don't support label indexing
Q4mcq1 mark
Two Series with only partially overlapping index labels are added together, and .head(3) is applied to the result. Positions where a label exists in only one of the two Series will show:
NaN ✓
0
The value from the Series that has it
The string 'missing'
Q5mcq1 mark
A Series s = pd.Series([2, 4, 6, 8], index=['w', 'x', 'y', 'z']) is sliced as s['x':'z'] and the result is then multiplied by 10. What happens to the index labels of the final result?
The index labels ('x', 'y', 'z') are preserved unchanged ✓
The index labels are converted to integers 0, 1, 2
The index labels are dropped entirely
The index labels are reversed
Q6mcq1 mark
A Series is created from the list [3, 6, 9, 12, 15], multiplied by 2, and then .head(3) is called on the result. Which value appears first in the output?
6 ✓
3
12
18
Q7mcq1 mark
A Series is created from a dictionary with four month-name keys inserted in the order jan, feb, mar, apr. Applying the positional slice s[1:3] on it will select elements based on:
Their position in insertion order, not their key names ✓
Alphabetical order of the key names
The numeric value of the data
A random order each time the code runs
Q8output1 mark
What is the output of the following code, which creates a Series from a dictionary, adds another Series to it, and then applies a label-based slice to the sum?
import pandas as pd
d = {'a': 10, 'b': 20, 'c': 30}
s1 = pd.Series(d)
s2 = pd.Series([1, 2, 3], index=['a', 'b', 'c'])
result = s1 + s2
print(result['b':'c'])
Correct output:
b 22
c 33
dtype: int64Q9output1 mark
What is the output of the following code?
import pandas as pd import numpy as np arr = np.array([100, 200, 300, 400, 500, 600]) s = pd.Series(arr, index=['p', 'q', 'r', 's', 't', 'u']) print(s.tail(2))
Correct output:
t 500
u 600
dtype: int64Q10output1 mark
What is the output of the following code?
import pandas as pd s = pd.Series(7, index=['m', 'n', 'o']) print(s['n'])
Correct output:
7Q11output1 mark
What is the output of the following code?
import pandas as pd s1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']) s2 = pd.Series([10, 20, 30, 40], index=['c', 'd', 'e', 'f']) combined = s1 + s2 print(combined.head(3))
Correct output:
a NaN
b NaN
c 13.0
dtype: float64Q12output1 mark
What is the output of the following code, which slices a Series by label and then multiplies the result by a scalar?
import pandas as pd s = pd.Series([2, 4, 6, 8], index=['w', 'x', 'y', 'z']) sliced = s['x':'z'] print(sliced * 10)
Correct output:
x 40
y 60
z 80
dtype: int64Q13output1 mark
What is the output of the following code?
import pandas as pd s = pd.Series([3, 6, 9, 12, 15]) print((s * 2).head(3))
Correct output:
0 6
1 12
2 18
dtype: int64Q14output1 mark
What is the output of the following code?
import pandas as pd
d = {'jan': 100, 'feb': 150, 'mar': 200, 'apr': 250}
s = pd.Series(d)
print(s[1:3])
Correct output:
feb 150
mar 200
dtype: int64Q15output1 mark
What is the output of the following code, which subtracts two Series and then indexes a single label from the result?
import pandas as pd s1 = pd.Series([5, 10, 15], index=['a', 'b', 'c']) s2 = pd.Series([1, 2, 3], index=['a', 'b', 'c']) diff = s1 - s2 print(diff['c'])
Correct output:
12