@@ -2281,37 +2281,71 @@ def _binop(self, other, func, level=None, fill_value=None):
2281
2281
2282
2282
def combine (self , other , func , fill_value = None ):
2283
2283
"""
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.
2287
2290
2288
2291
Parameters
2289
2292
----------
2290
- other : Series or scalar value
2293
+ other : Series or scalar
2294
+ The value(s) to be combined with the `Series`.
2291
2295
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.
2296
2301
2297
2302
Returns
2298
2303
-------
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.
2309
2306
2310
2307
See Also
2311
2308
--------
2312
2309
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
+ """
2315
2349
if fill_value is None :
2316
2350
fill_value = na_value_for_dtype (self .dtype , compat = False )
2317
2351
@@ -2352,16 +2386,26 @@ def combine(self, other, func, fill_value=None):
2352
2386
2353
2387
def combine_first (self , other ):
2354
2388
"""
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.
2357
2390
2358
2391
Parameters
2359
2392
----------
2360
2393
other : Series
2394
+ The value(s) to be combined with the `Series`.
2361
2395
2362
2396
Returns
2363
2397
-------
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.
2365
2409
2366
2410
Examples
2367
2411
--------
@@ -2371,11 +2415,6 @@ def combine_first(self, other):
2371
2415
0 1.0
2372
2416
1 4.0
2373
2417
dtype: float64
2374
-
2375
- See Also
2376
- --------
2377
- Series.combine : Perform elementwise operation on two Series
2378
- using a given function.
2379
2418
"""
2380
2419
new_index = self .index .union (other .index )
2381
2420
this = self .reindex (new_index , copy = False )
0 commit comments