CBSE Class 12 Informatics Practices Question 113 of 167

Python Pandas — I — Question 3

Back to all questions
3
Question

Question 3

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
Output
pencils      37
notebooks    46
scales       83
erasers      42
dtype: int64
pencils       54
notebooks     59
scales       114
erasers       74
dtype: int64
Explanation

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.