CBSE Class 12 Informatics Practices Question 18 of 44

Data Handling using Pandas — Question 19

Back to all questions
19
Question

Question 17(c)

Find the error in the following code fragments:

S1 = pd.Series(1, 2, 3, 4, index = range(7))
Answer

In the above code fragment, the data values should be enclosed in square brackets to form a list and the specified index range range(7) is out of range for the provided data [1, 2, 3, 4]. Since there are only four 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], index = range(4))