Skip to content
Advertisement

how to multiply pandas dataframe with numpy array with broadcasting

I have a dataframe of shape (4, 3) as following:

JavaScript

I want to multiply each column of the dataframe with a numpy array of shape (4,):

JavaScript

In numpy, the following broadcasting trick works:

JavaScript

However, it doesn’t work in the case of pandas dataframe, I get the following error:

JavaScript

Any suggestions?

Advertisement

Answer

I find an alternative way to do the multiplication between pandas dataframe and numpy array.

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