Skip to content

Commit 535b0a2

Browse files
topper-123TomAugspurger
authored andcommitted
updated (Series/DataFrame).combine doc strings (#18268)
(cherry picked from commit 1e30886)
1 parent 9eb3bc9 commit 535b0a2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pandas/core/frame.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -4035,15 +4035,30 @@ def combine(self, other, func, fill_value=None, overwrite=True):
40354035
----------
40364036
other : DataFrame
40374037
func : function
4038+
Function that takes two series as inputs and return a Series or a
4039+
scalar
40384040
fill_value : scalar value
40394041
overwrite : boolean, default True
40404042
If True then overwrite values for common keys in the calling frame
40414043
40424044
Returns
40434045
-------
40444046
result : DataFrame
4045-
"""
40464047
4048+
Examples
4049+
--------
4050+
>>> df1 = DataFrame({'A': [0, 0], 'B': [4, 4]})
4051+
>>> df2 = DataFrame({'A': [1, 1], 'B': [3, 3]})
4052+
>>> df1.combine(df2, lambda s1, s2: s1 if s1.sum() < s2.sum() else s2)
4053+
A B
4054+
0 0 3
4055+
1 0 3
4056+
4057+
See Also
4058+
--------
4059+
DataFrame.combine_first : Combine two DataFrame objects and default to
4060+
non-null values in frame calling the method
4061+
"""
40474062
other_idxlen = len(other.index) # save for compare
40484063

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

pandas/core/series.py

+15
Original file line numberDiff line numberDiff line change
@@ -1731,11 +1731,26 @@ 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 : Combine Series values, choosing the calling
1753+
Series's values first
17391754
"""
17401755
if isinstance(other, Series):
17411756
new_index = self.index.union(other.index)

0 commit comments

Comments
 (0)