Pandas/Python multiply columns by row

人走茶凉 提交于 2019-12-02 11:49:28

You can use mul by first row of df1 selected by iloc:

print (df2.mul(df1.iloc[0]))

Sample:

print (df1)
      51200000.0  70000000.0
age                        
0          0.75        0.25

print (df2)
      51200000.0  70000000.0
age                         
91.0         1.0         2.0
94.0         5.0        10.0
96.0         0.0         0.0

print (df2.mul(df1.iloc[0]))
      51200000.0  70000000.0
age                         
91.0        0.75         0.5
94.0        3.75         2.5
96.0        0.00         0.0
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!