Question:medium

Write the output of the following code:

import pandas as pd
s1 = pd.Series ([1, 2, 3], index = ['a','b','c'])
s2 = pd.Series ([4, 5, 6], index = ['b','c','d'])
print (s1 + S2)

Show Hint

Pandas adds Series values by matching index labels. A label found in only one Series gives NaN, and the result becomes float.
Updated On: Oct 20, 2026
Show Solution

Solution and Explanation

Step 1: Spot the name problem first:
The Series made in the code is called s2, but the print line uses S2. As typed, Python cannot find S2 and stops with NameError: name 'S2' is not defined.
This looks like a printing slip, so the answer below treats it as s2.

Step 2: Line up the labels:
Write the labels of both Series in one list. The combined labels are a, b, c, d.
Under each label put the value from s1 and from s2, and write a dash where a Series has no such label.
a: 1 and -. b: 2 and 4. c: 3 and 5. d: - and 6.

Step 3: Apply the rule:
Addition needs a number from both sides. Where one side is missing, Pandas puts NaN in the result.
So a becomes NaN and d becomes NaN.

Step 4: Do the sums:
b: 2 + 4 = 6.
c: 3 + 5 = 8.
As the column now has NaN, Pandas stores every value as float. So 6 is shown as 6.0 and 8 as 8.0, and the dtype is float64.

Final Answer:
a    NaN
b    6.0
c    8.0
d    NaN
dtype: float64
Was this answer helpful?
0