Informatics Practices
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))
Related Questions
Find the error in the following code fragments:
S = pd.Series(2, 3, 4, 55, index = range (4))Find the error in following code fragment
S1 = pd.Series(1, 2, 3, 4, index = range(7))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 ?
Why does the following code cause error?
s1 = pd.Series(range 1, 15, 5), index = list('ababa') print(s1['ab'])