@@ -2281,37 +2281,71 @@ def _binop(self, other, func, level=None, fill_value=None):
22812281
22822282 def combine (self , other , func , fill_value = None ):
22832283 """
2284- Perform elementwise binary operation on two Series using given function
2285- with optional fill value when an index is missing from one Series or
2286- the other
2284+ Combine the Series with a Series or scalar according to `func`.
2285+
2286+ Combine the Series and `other` using `func` to perform elementwise
2287+ selection for combined Series.
2288+ `fill_value` is assumed when value is missing at some index
2289+ from one of the two objects being combined.
22872290
22882291 Parameters
22892292 ----------
2290- other : Series or scalar value
2293+ other : Series or scalar
2294+ The value(s) to be combined with the `Series`.
22912295 func : function
2292- Function that takes two scalars as inputs and return a scalar
2293- fill_value : scalar value
2294- The default specifies to use the appropriate NaN value for
2295- the underlying dtype of the Series
2296+ Function that takes two scalars as inputs and returns an element.
2297+ fill_value : scalar, optional
2298+ The value to assume when an index is missing from
2299+ one Series or the other. The default specifies to use the
2300+ appropriate NaN value for the underlying dtype of the Series.
22962301
22972302 Returns
22982303 -------
2299- result : Series
2300-
2301- Examples
2302- --------
2303- >>> s1 = pd.Series([1, 2])
2304- >>> s2 = pd.Series([0, 3])
2305- >>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2)
2306- 0 0
2307- 1 2
2308- dtype: int64
2304+ Series
2305+ The result of combining the Series with the other object.
23092306
23102307 See Also
23112308 --------
23122309 Series.combine_first : Combine Series values, choosing the calling
2313- Series's values first.
2314- """
2310+ Series' values first.
2311+
2312+ Examples
2313+ --------
2314+ Consider 2 Datasets ``s1`` and ``s2`` containing
2315+ highest clocked speeds of different birds.
2316+
2317+ >>> s1 = pd.Series({'falcon': 330.0, 'eagle': 160.0})
2318+ >>> s1
2319+ falcon 330.0
2320+ eagle 160.0
2321+ dtype: float64
2322+ >>> s2 = pd.Series({'falcon': 345.0, 'eagle': 200.0, 'duck': 30.0})
2323+ >>> s2
2324+ falcon 345.0
2325+ eagle 200.0
2326+ duck 30.0
2327+ dtype: float64
2328+
2329+ Now, to combine the two datasets and view the highest speeds
2330+ of the birds across the two datasets
2331+
2332+ >>> s1.combine(s2, max)
2333+ duck NaN
2334+ eagle 200.0
2335+ falcon 345.0
2336+ dtype: float64
2337+
2338+ In the previous example, the resulting value for duck is missing,
2339+ because the maximum of a NaN and a float is a NaN.
2340+ So, in the example, we set ``fill_value=0``,
2341+ so the maximum value returned will be the value from some dataset.
2342+
2343+ >>> s1.combine(s2, max, fill_value=0)
2344+ duck 30.0
2345+ eagle 200.0
2346+ falcon 345.0
2347+ dtype: float64
2348+ """
23152349 if fill_value is None :
23162350 fill_value = na_value_for_dtype (self .dtype , compat = False )
23172351
@@ -2352,16 +2386,26 @@ def combine(self, other, func, fill_value=None):
23522386
23532387 def combine_first (self , other ):
23542388 """
2355- Combine Series values, choosing the calling Series's values
2356- first. Result index will be the union of the two indexes
2389+ Combine Series values, choosing the calling Series's values first.
23572390
23582391 Parameters
23592392 ----------
23602393 other : Series
2394+ The value(s) to be combined with the `Series`.
23612395
23622396 Returns
23632397 -------
2364- combined : Series
2398+ Series
2399+ The result of combining the Series with the other object.
2400+
2401+ See Also
2402+ --------
2403+ Series.combine : Perform elementwise operation on two Series
2404+ using a given function.
2405+
2406+ Notes
2407+ -----
2408+ Result index will be the union of the two indexes.
23652409
23662410 Examples
23672411 --------
@@ -2371,11 +2415,6 @@ def combine_first(self, other):
23712415 0 1.0
23722416 1 4.0
23732417 dtype: float64
2374-
2375- See Also
2376- --------
2377- Series.combine : Perform elementwise operation on two Series
2378- using a given function.
23792418 """
23802419 new_index = self .index .union (other .index )
23812420 this = self .reindex (new_index , copy = False )
0 commit comments