Table Of Contents

Search

Enter search terms or a module, class or function name.

pandas.DataFrame.rmod

DataFrame.rmod(other, axis='columns', level=None, fill_value=None)[source]

Modulo of dataframe and other, element-wise (binary operator rmod).

Equivalent to other % dataframe, but with support to substitute a fill_value for missing data in one of the inputs.

Parameters:
other : Series, DataFrame, or constant

axis : {0, 1, ‘index’, ‘columns’}

For Series input, axis to match Series index on

level : int or name

Broadcast across a level, matching Index values on the passed MultiIndex level

fill_value : None or float value, default None

Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing

Returns:
result : DataFrame

See also

DataFrame.mod

Notes

Mismatched indices will be unioned together

Examples

Using a scalar argument

>>> df = pd.DataFrame([2, 4, np.nan, 6.2], index=["a", "b", "c", "d"],
...                   columns=['one'])
>>> df
    one
a   2.0
b   4.0
c   NaN
d   6.2
>>> df.mod(3, fill_value=-1)
    one
a   2.0
b   1.0
c   2.0
d   0.2

Using a DataFrame argument

>>> df = pd.DataFrame(dict(one=[np.nan, 2, 3, 14], two=[np.nan, 1, 1, 3]),
...                   index=['a', 'b', 'c', 'd'])
>>> df
    one   two
a   NaN   NaN
b   2.0   1.0
c   3.0   1.0
d   14.0  3.0
>>> other = pd.DataFrame(dict(one=[np.nan, np.nan, 6, np.nan],
...                           three=[np.nan, 10, np.nan, -7]),
...                      index=['a', 'b', 'd', 'e'])
>>> other
    one three
a   NaN NaN
b   NaN 10.0
d   6.0 NaN
e   NaN -7.0
>>> df.mod(other, fill_value=3)
    one   three two
a   NaN   NaN   NaN
b   2.0   3.0   1.0
c   0.0   NaN   1.0
d   2.0   NaN   0.0
e   NaN  -4.0   NaN
Scroll To Top