Informatics Practices

Find the error in the following code fragments:

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

Python Data Handling

2 Likes

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))

Answered By

1 Like


Related Questions