Multiply two data frames with similar index in python pandas -
i have 2 data frames , want multiply them index. best way this? note: column names different.
df1 = pd.dataframe([(1,2,3),(3,4,5),(5,6,7)], columns=['a','b','d'], index = ['a', 'b','c']) df1 b d 1 2 3 b 3 4 5 c 5 6 7 df2 = pd.dataframe([(10,20,30)], columns=['a','b','c'],index = ['ss']) df2 = df2.transpose() df2 ss 10 b 20 c 30 output dataframe:
b d 10 20 30 b 60 80 100 c 150 180 210
call mul , convert series list , pass axis=0, converting list ignore alignment errors index/column names:
in [74]: df1.mul(list(df2['ss']), axis=0) out[74]: b d 10 20 30 b 60 80 100 c 150 180 210 edit
no need convert list access series directly:
in [75]: df1.mul(df2['ss'], axis=0) out[75]: b d 10 20 30 b 60 80 100 c 150 180 210
Comments
Post a Comment