CBSE Class 12 Informatics Practices Question 19 of 44

Data Handling using Pandas — Question 20

Back to all questions
20
Question

Question 17(d)

Find the error in the following code fragments:

S2 = pd.Series([1, 2, 3, 4, 5], index = range(4))
Answer

The error in the code fragment is that the length of the data list [1, 2, 3, 4, 5] does not match the length of the index range(4). Since there are only five data values, the index should have a length that matches the number of data values.

The corrected code is:

S1 = pd.Series([1, 2, 3, 4, 5], index = range(5))