Skip to content
Advertisement

How to multiply all numerical columns of a dataframe by a one-dimensional array?

I have a dataframe df of shape r x c, with 1 text column (with non-unique values) and the other columns all floats. I then have an array mult of size r. I would like each numerical column of the dataframe to be multiplied by the corresponding item of the array.

Ie the desired output is that value_1[0] should become value_1[0] * mult[0], value_2[0] should become value_2[0] * mult[0], etc.

What is an easy way to do it?

I have tried the code below but it doesn’t work.

JavaScript

Advertisement

Answer

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