pandas.Series.combine_first#
- Series.combine_first(other)[源代码]#
用 ‘other’ 中相同位置的值更新空元素。
通过用一个 Series 中的非空值填充另一个 Series 中的空值来组合两个 Series 对象。结果索引将是两个索引的并集。
- Parameters:
- otherSeries
用于填充空值的值。
- Returns:
- Series
组合提供的 Series 与其他对象的serult。
参见
Series.combine使用给定的函数对两个 Series 执行逐元素操作。
Examples
>>> 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