pandas.Series.combine_first#
- Series.combine_first(other)[源代码]#
使用‘Other’中相同位置的值更新空元素。
通过使用另一个系列中的非空值填充一个系列中的空值来合并两个系列对象。结果索引将是这两个索引的并集。
- 参数
- other系列
要用于填充空值的值。
- 退货
- 系列
将提供的系列与其他对象组合的结果。
参见
Series.combine
使用给定函数对两个级数执行逐个元素的运算。
示例
>>> 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