當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pandas.Series.combine_first用法及代碼示例

用法:

Series.combine_first(other)

使用 ‘other’ 中相同位置的值更新 null 元素。

通過將一個 Series 中的 null 值與另一個 Series 中的非 null 值填充來組合兩個 Series 對象。結果索引將是兩個索引的並集。

參數

otherSeries

用於填充空值的值。

返回

Series

將提供的 Series 與其他對象組合的結果。

例子

>>> s1 = pd.Series([1, np.nan])
>>> s2 = pd.Series([3, 4, 5])
>>> s1.combine_first(s2)
0    1.0
1    4.0
2    5.0
dtype:float64

如果空值的位置在other 中不存在,空值仍然存在

>>> s1 = pd.Series({'falcon':np.nan, 'eagle':160.0})
>>> s2 = pd.Series({'eagle':200.0, 'duck':30.0})
>>> s1.combine_first(s2)
duck       30.0
eagle     160.0
falcon      NaN
dtype:float64

相關用法


注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.combine_first。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。