Python | Pandas dataframe.rmod ()

Python Methods and Functions

The Pandas function dataframe.rmod() is used to find the data module and other elements (binary operator rfloordiv). This function is essentially the same as for other% dataframe but with support for replacing missing data in one of the inputs.

Syntax: DataFrame.rmod (other, axis = 'columns', level = None, fill_value = None)

Parameters:
other: Series, DataFrame, or constant
axis: For Series input, axis to match Series index on
level: Broadcast across a level, matching Index values on the passed MultiIndex leve
fill_value: 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

Example # 1: Use rmod () to find the rmod () data frame row.

# import pandas as pd

import pandas as pd

 
# Create data frame

df = pd.DataFrame ({ "A" : [ 1 , 5 , 3 , 4 , 2 ],

  " B " : [ 3 , 2 , 4 , 3 , 4 ],

"C" : [ 2 , 2 , 7 , 3 , 4 ],

"D" : [ 4 , 3 , 6 , 12 , 7 ]},

index = [ "A1" , "A2" , "A3" , "A4" , "A5" ])

 
# Print data frame
df

Let's create a series y

# import pandas as pd

import pandas as pd

 
# Create episode

sr = pd.Series ([ 12 , 25 , 64 , 18 ], index = [ "A" , "B" , "C " , " D " ])

  
# Print series
sr

Let's use the dataframe.rmod () function to find the dataframe row module

df. rmod (sr, axis = 1 )

Output:

Example # 2: Use rmod () to do modulo division data frame with another.

# import pandas as pd

import pandas as pd

 
# Create first data frame

df1 = pd.DataFrame ({ "A" : [ 1 , 5 , 3 , 4 , 2 ],

"B" : [ 3 , 2 , 4 , 3 , 4 ], 

  "C" : [ 2 , 2 , 7 , 3 , 4 ],

"D" : [ 4 , 3 , 6 , 12 , 7 ]},

index = [ "A1" , "A2" , "A3" , "A4" , "A5" ])

 
# Create second data frame

df2 = pd.DataFrame ({ "A" : [ 10 , 11 , 7 , 8 , 5 ],

"B" : [ 2 1 , 5 , 32 , 4 , 6 ],

"C" : [ 11 , 21 , 23 , 7 , 9 ],

"D" : [ 1 , 5 , 3 , 8 , 6 ]}, 

index = [ "A1" , "A2" , "A3" , "A4" , "A5" ])

 
# execute df2 module by df1
df1.rmod (df2)

Output:





Get Solution for free from DataCamp guru