pandas.Series.add中参数fill_value的小疑惑

pandas.Series.add

Series.add(other, level=None, fill_value=None, axis=0)

Examples

>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a
a   1.0
b   1.0
c   1.0
d   NaN
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b
a    1.0
b    NaN
d    1.0
e    NaN
dtype: float64
>>> a.add(b, fill_value=0)
a    2.0
b    1.0
c    1.0
d    1.0
e    NaN
dtype: float64

From pandas 0.24.2 documentation

我没弄不明白参数fill_value具体咋样,然后查了一些资料

该参数使a中value的NaN=fill_value,然后与b中相同索引的value相加

注意:缺失值NaN与任何值相加的结果均为NaN,所以这就是为什么要用到fill_value的原因啦

猜你喜欢

转载自www.cnblogs.com/ricecake/p/11296330.html