Informatics Practices
Consider the same Series object, S, given in the previous question. What output will be produced by following code fragment ?
S.index = ['AMZN', 'AAPL', 'MSFT', 'GOOG']
print(S)
print(S['AMZN'])
S['AMZN'] = 1.5
print(S['AMZN'])
print(S)
Python Pandas
2 Likes
Answer
AMZN 0.430271
AAPL 0.617328
MSFT -0.265421
GOOG -0.836113
dtype: float64
0.430271
1.5
AMZN 1.500000
AAPL 0.617328
MSFT -0.265421
GOOG -0.836113
dtype: float64
Working
The provided code fragment first changes the index labels of the Series S
to ['AMZN', 'AAPL', 'MSFT', 'GOOG'], prints the modified Series S
, and then proceeds to print and modify the value corresponding to the 'AMZN' index. Specifically, it prints the value at the 'AMZN' index before and after assigning a new value of 1.5 to that index. Finally, it prints the Series S
again, showing the updated value at the 'AMZN' index.
Answered By
1 Like
Related Questions
Which function would you use to rename the index/column names in a dataframe ?
Consider following Series object namely S :
0 0.430271 1 0.617328 2 -0.265421 3 -0.836113 dtype:float64
What will be returned by following statements ?
(a) S * 100
(b) S > 0
(c) S1 = pd.Series(S)
(d) S2 = pd.Series(S1) + 3
What will be the values of Series objects S1 and S2 created above ?
What will be the output produced by the following code ?
Stationery = ['pencils', 'notebooks', 'scales', 'erasers'] S = pd.Series([20, 33, 52, 10], index = Stationery) S2 = pd.Series([17, 13, 31, 32], index = Stationery) print(S + S2) S = S + S2 print(S + S2)
What will be the output produced by following code, considering the Series object S given above ?
(a) print(S[1:1])
(b) print(S[0:1])
(c) print(S[0:2])
(d)
S[0:2] = 12 print(S)
(e)
print(S.index) print(S.values)