Skip to main contentSkip to solution

When adding two Series objects with a common index, but one of them has a missing value, then what will be the default value in front of missing index?

Solution

✅ Correct Option: 1

Pandas aligns two Series on their index labels before adding. If a label is present in one Series but missing (or holds NaN) in the other, the result at that label is NaN, because any arithmetic with NaN gives NaN. No error is raised.

For example, pd.Series([1, 2], index=['a', 'b']) + pd.Series([10], index=['a']) gives 11 for a and NaN for b.


Option 4: the other Series' value is used only if you call s1.add(s2, fill_value=0), which treats the missing value as 0. The + operator does not do this.

Option 3: pandas does not raise an error for mismatched or missing indexes during arithmetic.

Keyboard Shortcuts

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