Skip to content

Commit 4dc05b5

Browse files
Kurtis Kersteinjorisvandenbossche
Kurtis Kerstein
authored andcommitted
DOC: update the DataFrame.sub docstring (#20358)
1 parent 6bac7e4 commit 4dc05b5

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

pandas/core/ops.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,33 @@ def _get_op_name(op, special):
370370
e NaN 2.0
371371
"""
372372

373+
_sub_example_FRAME = """
374+
>>> a = pd.DataFrame([2, 1, 1, np.nan], index=['a', 'b', 'c', 'd'],
375+
... columns=['one'])
376+
>>> a
377+
one
378+
a 2.0
379+
b 1.0
380+
c 1.0
381+
d NaN
382+
>>> b = pd.DataFrame(dict(one=[1, np.nan, 1, np.nan],
383+
... two=[3, 2, np.nan, 2]),
384+
... index=['a', 'b', 'd', 'e'])
385+
>>> b
386+
one two
387+
a 1.0 3.0
388+
b NaN 2.0
389+
d 1.0 NaN
390+
e NaN 2.0
391+
>>> a.sub(b, fill_value=0)
392+
one two
393+
a 1.0 -3.0
394+
b 1.0 -2.0
395+
c 1.0 NaN
396+
d -1.0 NaN
397+
e NaN -2.0
398+
"""
399+
373400
_op_descriptions = {
374401
# Arithmetic Operators
375402
'add': {'op': '+',
@@ -379,7 +406,7 @@ def _get_op_name(op, special):
379406
'sub': {'op': '-',
380407
'desc': 'Subtraction',
381408
'reverse': 'rsub',
382-
'df_examples': None},
409+
'df_examples': _sub_example_FRAME},
383410
'mul': {'op': '*',
384411
'desc': 'Multiplication',
385412
'reverse': 'rmul',

0 commit comments

Comments
 (0)