I am having pandas dataframe like this
A B D E
2 12 1 2
3 54 1 4
10 2 1 1
I would like to multiply values in C and D column by the value in A, but keep values in B column. So from the dataframe above, the result I would get would be :
A B D E
2 12 2 4
3 54 3 12
10 2 10 10
However, I have many columns I want to modify, not just 2 like in the example. Therefore I would like to know what is the most efficient way to do this.
I was looking at DataFrame.assign function but with that, it seems like I can only modify 1 column at the time.
Thanks !
df[col_list] * df['A']just work?df.loc[:,col_list] = df[col_list] * df['A']and surprisingly it got me NaNs in all the col_list columns. I wonder why, the datatype in both col_list collumns and "A" columns are numpy.float64df[col_list] = df[col_list].mul(df['A'], axis=0)NaNvalues returned, if you did this then it would work:(df[col_list].T * df['A']).Tbut this isn't so pretty