Search code examples
pandasmultiple-columnsscalarmultiplication

Mutiply DataFrame columns with different weights


I need to multiply individual columns in a dataframe by weights. So I have the following code

df.C1 *= 0.2
df.C2 *= 0.01

Is there a better or short way of doing it, possibly a list of weights multiplied to columns?

Something like df.cols.values *= list(weights)


Solution

  • Something like

    df1.loc[:,cols]=df1[cols].values*[100,10]