@@ -2992,34 +2992,46 @@ def combine(self, other, func, fill_value=None) -> Series:
2992
2992
2993
2993
def combine_first (self , other ) -> Series :
2994
2994
"""
2995
- Combine Series values, choosing the calling Series's values first.
2995
+ Update null elements with value in the same location in 'other'.
2996
+
2997
+ Combine two Series objects by filling null values in one Series with
2998
+ non-null values from the other Series. Result index will be the union
2999
+ of the two indexes.
2996
3000
2997
3001
Parameters
2998
3002
----------
2999
3003
other : Series
3000
- The value(s) to be combined with the `Series` .
3004
+ The value(s) to be used for filling null values .
3001
3005
3002
3006
Returns
3003
3007
-------
3004
3008
Series
3005
- The result of combining the Series with the other object.
3009
+ The result of combining the provided Series with the other object.
3006
3010
3007
3011
See Also
3008
3012
--------
3009
- Series.combine : Perform elementwise operation on two Series
3013
+ Series.combine : Perform element-wise operation on two Series
3010
3014
using a given function.
3011
3015
3012
- Notes
3013
- -----
3014
- Result index will be the union of the two indexes.
3015
-
3016
3016
Examples
3017
3017
--------
3018
3018
>>> s1 = pd.Series([1, np.nan])
3019
- >>> s2 = pd.Series([3, 4])
3019
+ >>> s2 = pd.Series([3, 4, 5 ])
3020
3020
>>> s1.combine_first(s2)
3021
3021
0 1.0
3022
3022
1 4.0
3023
+ 2 5.0
3024
+ dtype: float64
3025
+
3026
+ Null values still persist if the location of that null value
3027
+ does not exist in `other`
3028
+
3029
+ >>> s1 = pd.Series({'falcon': np.nan, 'eagle': 160.0})
3030
+ >>> s2 = pd.Series({'eagle': 200.0, 'duck': 30.0})
3031
+ >>> s1.combine_first(s2)
3032
+ duck 30.0
3033
+ eagle 160.0
3034
+ falcon NaN
3023
3035
dtype: float64
3024
3036
"""
3025
3037
new_index = self .index .union (other .index )
0 commit comments