CBSE Class 12 Informatics Practices Question 121 of 167

Python Pandas — I — Question 11

Back to all questions
11
Question

Question 8

Why does following code cause error ?

s1 = pd.Series(range(1, 15, 3), index = list('abcd'))
Answer

The code causes an error because the length of the data (range(1, 15, 3)) and the length of the index (list('abcd')) do not match. The range(1, 15, 3) generates the sequence [1, 4, 7, 10, 13], which has a length of 5. The list('abcd') generates the list ['a', 'b', 'c', 'd'], which has a length of 4. When creating a pandas Series, the length of the data and the length of the index must be the same.