sum of multiplication of cells in the same row but different column for pandas data frame

Viewed 4831

I have a data frame

df = pd.DataFrame({'A':[1,2,3],'B':[2,3,4]})

My data looks like this

Index   A   B
0       1   2
1       2   3
2       3   4

I would like to calculate the sum of multiplication between A and B in each row. The expected result should be (1x2)+(2x3)+(3x4) = 2 + 6 + 12 = 20. May I know the pythonic way to do this instead of looping?

1 Answers
Related