Skip to main contentSkip to solution

What will be the result when two Pandas Series being combined have mismatched indices?

Solution

✅ Correct Option: 2

When two Series are combined (for example with +), Pandas aligns them on their index labels. A label present in only one Series has no partner to operate with, so the result for that label is NaN. The result contains the union of both indices.

For example, pd.Series([1, 2], index=['a', 'b']) + pd.Series([10, 20], index=['b', 'c']) gives:

IndexResult
aNaN
b12.0
cNaN

Use s1.add(s2, fill_value=0) to treat a missing label as 0 instead of getting NaN.


Options 1 and 4: the mismatched labels are not removed. They stay in the result with NaN values, because Pandas takes the union of the indices, not the intersection.

Option 3: no error is raised. Alignment happens automatically.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question