pythonpandasdataframematrixdivide

Can two seperate matrix be divided and saved in a dataframe using python?


I have two matrix saved in dataframe.

df1                     df2

    0  1  2            0  1  2
0   4  6  2          0 2  3  2
1   2  0  6          1 1  3  2
2   8  2  1          2 4  2  3

Is it possible to calculate a third matrix where the elements of df1 gets divided by df2? What is the easiest wayto achieve the same in python? Thank you

Desired Output:
   0  1  2
0  2  2  1
1  2  0  3
2  2  0  0.33

Solution

  • df3 = df1.div(df2) 
    

    will create a new df after element wise division.