Skip to content

Commit c5870aa

Browse files
ailchauWillAyd
authored andcommitted
DOC: Update the examples to DataFrame.mod docstring (pandas-dev#20406)
1 parent da6e26d commit c5870aa

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

pandas/core/ops.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,52 @@ def _get_op_name(op, special):
401401
e NaN -2.0
402402
"""
403403

404+
_mod_example_FRAME = """
405+
**Using a scalar argument**
406+
407+
>>> df = pd.DataFrame([2, 4, np.nan, 6.2], index=["a", "b", "c", "d"],
408+
... columns=['one'])
409+
>>> df
410+
one
411+
a 2.0
412+
b 4.0
413+
c NaN
414+
d 6.2
415+
>>> df.mod(3, fill_value=-1)
416+
one
417+
a 2.0
418+
b 1.0
419+
c 2.0
420+
d 0.2
421+
422+
**Using a DataFrame argument**
423+
424+
>>> df = pd.DataFrame(dict(one=[np.nan, 2, 3, 14], two=[np.nan, 1, 1, 3]),
425+
... index=['a', 'b', 'c', 'd'])
426+
>>> df
427+
one two
428+
a NaN NaN
429+
b 2.0 1.0
430+
c 3.0 1.0
431+
d 14.0 3.0
432+
>>> other = pd.DataFrame(dict(one=[np.nan, np.nan, 6, np.nan],
433+
... three=[np.nan, 10, np.nan, -7]),
434+
... index=['a', 'b', 'd', 'e'])
435+
>>> other
436+
one three
437+
a NaN NaN
438+
b NaN 10.0
439+
d 6.0 NaN
440+
e NaN -7.0
441+
>>> df.mod(other, fill_value=3)
442+
one three two
443+
a NaN NaN NaN
444+
b 2.0 3.0 1.0
445+
c 0.0 NaN 1.0
446+
d 2.0 NaN 0.0
447+
e NaN -4.0 NaN
448+
"""
449+
404450
_op_descriptions = {
405451
# Arithmetic Operators
406452
'add': {'op': '+',
@@ -418,7 +464,7 @@ def _get_op_name(op, special):
418464
'mod': {'op': '%',
419465
'desc': 'Modulo',
420466
'reverse': 'rmod',
421-
'df_examples': None},
467+
'df_examples': _mod_example_FRAME},
422468
'pow': {'op': '**',
423469
'desc': 'Exponential power',
424470
'reverse': 'rpow',

0 commit comments

Comments
 (0)