w3resource

Pandas Series: rtruediv() function

Floating division of series and other in Pandas

The rtruediv() function is used to get floating division of series and other, element-wise (binary operator rtruediv).

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

Syntax:

Series.rtruediv(self, other, level=None, fill_value=None, axis=0)
Pandas Series rtruediv() function

Parameters:

Name Description Type/Default Value Required / Optional
other    Series or scalar value Required
fill_value Fill existing missing (NaN) values, and any new element needed for successful Series alignment, with this value before computation. If data in both corresponding Series locations is missing the result will be missing. None or float value
Default Value: None (NaN)
Required
level Broadcast across a level, matching Index values on the passed MultiIndex level. int or name Required

Returns: Series
The result of the operation.

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
x = pd.Series([2, 2, 2, np.nan], index=['p', 'q', 'r', 's'])
x

Output:

p    2.0
q    2.0
r    2.0
s    NaN
dtype: float64
Pandas Series rtruediv() function

Python-Pandas Code:

import numpy as np
import pandas as pd
y = pd.Series([1, np.nan, 2, np.nan], index=['p', 'q', 's', 't'])
y

Output:

p    1.0
q    NaN
s    2.0
t    NaN
dtype: float64
Pandas Series rtruediv() function

Python-Pandas Code:

import numpy as np
import pandas as pd
x = pd.Series([2, 2, 2, np.nan], index=['p', 'q', 'r', 's'])
y = pd.Series([1, np.nan, 2, np.nan], index=['p', 'q', 's', 't'])
x.rtruediv(y, fill_value=0)

Output:

p    0.5
q    0.0
r    0.0
s    inf
t    NaN
dtype: float64

Previous: Floating division of Pandas series
Next: Integer division of Pandas series and other, element-wise



Follow us on Facebook and Twitter for latest update.