Python | Pandas Series.truediv ()

Python Methods and Functions

Series.truediv() Pandas Series.truediv() executes Series .truediv () division of rows and others, element by element (binary operator truediv). This is equivalent to series / other , but with support for fill_value replacement for missing data in one of the inputs.

Syntax: Series.truediv ( other, level = None, fill_value = None, axis = 0)

Parameter:
other: Series or scalar value
fill_value: Fill existing missing (NaN) values ​​
level: Broadcast across a level, matching Index values ​​on the passed MultiIndex level

Returns: result: Series

Example # 1: Use Series.truediv () to perform division floating point numbers of this series object with a different scalar.

Output:

We will now use Series.truediv () to divide the floating point number of a given series object by another scalar.

 

# import pandas as pd

import pandas as pd

  
# Create series

sr = pd.Series ([ 19.5 , 16.8 , 22.78 , 20.124 , 18.1002 ])

  
# Print series

print (sr)

# split all 10 series elements

sr.truediv (other = 10 )

Output:

How we see in the output that Series.truediv () has successfully performed elementwise division of the given Series object.

Example # 1: Use Series.truediv () to perform floating point division of a given series object with another scalar. This Series object contains some missing values. Handle missing values.

# import pandas as pd

import pandas as pd

  
# Create series

sr = pd.Series ([ 19.5 , 16.8 , None , 22.78 , 20.124 , None , 18.1002 ])

 
# Printout Attach Series

print (sr)

Output:

We will now use Series.truediv () to divide the floating point number of a given series object by another scalar. fill in the missing values ​​by 100.

# split all elements of the series by 10
# Also fill in all missing spaces per 100

sr.truediv (other = 10 , fill_value = 100 )

Exit :

As we can see in the output, Series .truediv () has successfully performed elementwise division of the given Series object. It also replaced 100 in place of missing values ​​before doing division.





Tutorials