Skip to content
Advertisement

Pandas dataframe.dot division method

I am trying to divide two series of different length to return the matrix product dataframe of them.

I can multiply them using the dot method (from this answer):

JavaScript

I’ve tried the div method, but this just fills the dataframe with NaNs:

JavaScript

Likewise the standard division operator also returns the same result:

JavaScript

So I’m a bit stumped as to what the correct solution is to my problem.

Any help is gratefully appreciated.

Advertisement

Answer

To do an element wise division operation you can divide the values of each data frame like so:

JavaScript

which produces the desired matrix of

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement