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)

Python Data Handling

1 Like

Answer

pencils      False
notebooks    False
scales       False
erasers      False
dtype: bool
pencils      37
notebooks    46
scales       83
erasers      42
dtype: int64

Working

The code creates two pandas Series, S and S2, with the index Stationery which is a list. The code then compares S and S2 element-wise using the "==" operator, which returns a boolean Series indicating whether each pair of values is equal. Finally, the code adds S and S2 element-wise using the "+" operator, which returns a new Series with the summed values, and assigns the result back to S. The resulting S Series will have the same index as before i.e., Stationery.

Answered By

1 Like


Related Questions