How it works...

The add method works similarly to the plus operator but allows for more flexibility by providing the fill_value parameter to take the place of a non-matching index. In this problem, it makes sense to default the non-matching index value to 0, but you could have used any other number.

There will be occasions when each Series contains index labels that correspond to missing values. In this specific instance, when the two Series are added, the index label will still correspond to a missing value regardless if the fill_value parameter is used. To clarify this, take a look at the following example where the index label a corresponds to a missing value in each Series:

>>> s = pd.Series(index=['a', 'b', 'c', 'd'],
data=[np.nan, 3, np.nan, 1])
>>> s
a NaN b 3.0 c NaN d 1.0 dtype: float64

>>> s1 = pd.Series(index=['a', 'b', 'c'], data=[np.nan, 6, 10])
>>> s1
a NaN
b 6.0
c 10.0
dtype: float64

>>> s.add(s1, fill_value=5)
a NaN b 9.0 c 15.0 d 6.0 dtype: float64
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.104.27