Amartya
Amartya

Reputation: 173

How to perform multiplication of a column value row wise with another dataframe?

I have a dataframe like this enter image description here. And I have to multiply the 'Factor' column value row wise with another dataframe enter image description here


I want result like this

enter image description here

I have tried with df.mul. But it is giving me all NAN values. How to get this resultant matrix using python

Upvotes: 0

Views: 675

Answers (2)

MoRe
MoRe

Reputation: 2362

pd.DataFrame(df2.to_numpy() * df1.to_numpy())

Upvotes: 3

Rabinzel
Rabinzel

Reputation: 7903

df2.apply(lambda x: x * df1['factor'])

Upvotes: 1

Related Questions