CBSE Class 12 Informatics Practices
Question 116 of 167
Python Pandas — I — Question 6
Back to all questionsS2 = pd.Series([101, 102, 102, 104])
print(S2.index)
S2.index = [0, 1, 2, 3, 4, 5] #Error 1
S2[5] = 220
print(S2) Error 1 — The Series S2 initially has four elements, so assigning a new index list of six elements ([0, 1, 2, 3, 4, 5]) to S2.index will raise a ValueError because the new index list length does not match the length of the Series.
The corrected code is:
S2 = pd.Series([101, 102, 102, 104])
print(S2.index)
S2.index = [0, 1, 2, 3]
S2[5] = 220
print(S2)