Skip to content

Commit 3a9da3c

Browse files
author
tp
committed
updated (Series/DataFrame).combine doc strings
1 parent 7f4c960 commit 3a9da3c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pandas/core/frame.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -4029,15 +4029,29 @@ def combine(self, other, func, fill_value=None, overwrite=True):
40294029
----------
40304030
other : DataFrame
40314031
func : function
4032+
Function that takes two series as inputs and return a Series or a
4033+
scalar
40324034
fill_value : scalar value
40334035
overwrite : boolean, default True
40344036
If True then overwrite values for common keys in the calling frame
40354037
40364038
Returns
40374039
-------
40384040
result : DataFrame
4039-
"""
40404041
4042+
Examples
4043+
--------
4044+
>>> df1 = DataFrame({'A': [0, 0], 'B': [4, 4]})
4045+
>>> df2 = DataFrame({'A': [1, 1], 'B': [3, 3]})
4046+
>>> df1.combine(df2, lambda s1, s2: s1 if s1.sum() < s2.sum() else s2)
4047+
A B
4048+
0 0 3
4049+
1 0 3
4050+
4051+
See Also
4052+
--------
4053+
DataFrame.combine_first
4054+
"""
40414055
other_idxlen = len(other.index) # save for compare
40424056

40434057
this, other = self.align(other, copy=False)

pandas/core/series.py

+14
Original file line numberDiff line numberDiff line change
@@ -1731,11 +1731,25 @@ def combine(self, other, func, fill_value=np.nan):
17311731
----------
17321732
other : Series or scalar value
17331733
func : function
1734+
Function that takes two scalars as inputs and return a scalar
17341735
fill_value : scalar value
17351736
17361737
Returns
17371738
-------
17381739
result : Series
1740+
1741+
Examples
1742+
--------
1743+
>>> s1 = Series([1, 2])
1744+
>>> s2 = Series([0, 3])
1745+
>>> s1.combine(s2, lambda x1, x2: x1 if x1 < x2 else x2)
1746+
0 0
1747+
1 2
1748+
dtype: int64
1749+
1750+
See Also
1751+
--------
1752+
Series.combine_first
17391753
"""
17401754
if isinstance(other, Series):
17411755
new_index = self.index.union(other.index)

0 commit comments

Comments
 (0)