Informatics Practices
Find the error in following code fragment
S1 = pd.Series(1, 2, 3, 4, index = range(7))
Python Pandas
3 Likes
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))
Answered By
2 Likes
Related Questions
Find the error in following code fragment :
S2 = pd.Series([101, 102, 102, 104]) print(S2.index) S2.index = [0, 1, 2, 3, 4, 5] S2[5] = 220 print(S2)Find the error in following code fragment :
S = pd.Series(2, 3, 4, 5, index = range(4))Find the error in following code fragment :
S2 = pd.Series([1, 2, 3, 4], index = range(4))Find the Error :
data = np.array(['a', 'b', 'c', 'd', 'e', 'f']) s = pd.Series(data, index = [100, 101, 102, 103, 104, 105]) print(s[102, 103, 104] )Can you correct the error ?