Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas two dataframes multiplication?

I have two data frames (A and B)

A:
column 1, column 2, column 3
0.1        0.5       0.7


B:
row 1          5
row 2          6
row 3          7

how do I perform multiplication to get like

(0.1)*5,  (0.5)* 6,  and (0.7)*7?

In other words, how do I multiply the value in the first row of B with the value in the first column of A, the second row of B with the value in the second column of B, and etc?

like image 455
Jun Jang Avatar asked Nov 28 '25 06:11

Jun Jang


1 Answers

you want to multiply their values without respect to whether they are rows or columns.

pd.Series(A.values.ravel() * B.values.ravel())

0    0.5
1    3.0
2    4.9
dtype: float64
like image 161
piRSquared Avatar answered Nov 30 '25 19:11

piRSquared