Skip to content

Commit 6d1dae6

Browse files
committed
clearer examples and PEP8, linting fixes
1 parent 06e5af0 commit 6d1dae6

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

pandas/core/series.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,47 +2281,61 @@ def _binop(self, other, func, level=None, fill_value=None):
22812281

22822282
def combine(self, other, func, fill_value=None):
22832283
"""
2284-
Combine the Series with a `Series` or `Scalar` according to `func`.
2284+
Combine the Series with a Series or Scalar according to `func`.
22852285
22862286
Perform elementwise binary operation on two Series using given function
2287-
with optional fill value when an index is missing from one Series or
2288-
the other.
2287+
with optional `fill_value` when an index is missing from the Series or
2288+
the other value.
22892289
22902290
Parameters
22912291
----------
2292-
other : Series or scalar value
2292+
other : Series or Scalar
22932293
The value(s) to be combined with the `Series`.
2294-
func : function
2295-
Function that takes two scalars as inputs and return a scalar.
2296-
fill_value : scalar value
2294+
func : Function
2295+
`function` that takes two Scalars as inputs and returns a `bool`.
2296+
fill_value : Scalar
22972297
The optional value to assume when an index
22982298
is missing from one Series or the other,
22992299
The default specifies to use the appropriate NaN value for
23002300
the underlying dtype of the Series.
23012301
23022302
Returns
23032303
-------
2304-
result : the combined `Series` object
2304+
A Series object.
23052305
23062306
Examples
23072307
--------
2308-
>>> s1 = pd.Series([1, 2])
2309-
>>> s2 = pd.Series([0, 3, 4])
2308+
>>> import pandas as pd
2309+
>>> s1 = pd.Series([1,2])
2310+
>>> s2 = pd.Series([0,3])
23102311
>>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2)
23112312
0 0
23122313
1 2
2314+
dtype: int64
2315+
2316+
>>> s2 = pd.Series([0,3,4])
2317+
>>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2)
2318+
0 1
2319+
1 3
23132320
2 4
23142321
dtype: int64
2315-
>>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2,fill_value=787)
2322+
2323+
When fill_value is given:-
2324+
2325+
>>> s1.combine(s2, lambda x1, x2: x1 if x1 > x2 else x2,
2326+
... fill_value = 787)
23162327
0 1
23172328
1 3
23182329
2 787
23192330
dtype: int64
23202331
2332+
If `func` doesn't get a value from either of the two Series,
2333+
fill_value` is used.
2334+
23212335
See Also
23222336
--------
23232337
Series.combine_first : Combine Series values, choosing the calling
2324-
Series's values first.
2338+
Series' values first
23252339
"""
23262340
if fill_value is None:
23272341
fill_value = na_value_for_dtype(self.dtype, compat=False)

0 commit comments

Comments
 (0)