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)

Python Pandas

5 Likes

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.

Answered By

2 Likes


Related Questions