Matrix Multiplication of a Pandas DataFrame and Series Matrix Multiplication of a Pandas DataFrame and Series pandas pandas

Matrix Multiplication of a Pandas DataFrame and Series


pandas implicity aligns on the index of a series, use the dot function

In [3]: df = pd.DataFrame({'a' : [4,1,3], 'b' : [5,2,4]},index=[1,2,3])In [4]: s = pd.Series([0.6,0.4],index=['a','b'])In [5]: df.dot(s)Out[5]: 1    4.42    1.43    3.4