Informatics Practices
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)
Answer
pencils 37
notebooks 46
scales 83
erasers 42
dtype: int64
pencils 54
notebooks 59
scales 114
erasers 74
dtype: int64
Working
The code creates two Pandas Series, S and S2. It then prints the result of adding these two Series element-wise based on their corresponding indices. After updating S by adding S and S2, it prints the result of adding updated S and S2 again.
Related Questions
Consider following Series object namely S :
0 0.430271 1 0.617328 2 -0.265421 3 -0.836113 dtype:float64What 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 ?
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)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)Write a Python program to create a series object, country using a list that stores the capital of each country.
Note. Assume four countries to be used as index of the series object are India, UK, Denmark and Thailand having their capitals as New Delhi, London, Copenhagen and Bangkok respectively.