如何将行中的所有元素与 Python 中 pandas 数据框中不同列中同一行中的相应元素相乘?

How to multiply all elements in a row with corresponding element in same row in different column in pandas dataframe in Python?

我有一个如下所示的数据框:

我想将除“depreciation_rate”列以外的行中的元素与“depreciation_rate”列中同一行中的值相乘。

我尝试了 df2.iloc[:,6:26]*df2["depreciation_rate"] 以及 df2.iloc[:,6:26].mul(df2["depreciation_rate"])

我得到的结果相同,如下所示。我得到 NaN 值和我不想要的附加列。我认为行中的元素也会与“depreciation_rate”列中其他行中的值相乘。解决这个问题的好方法是什么?

尝试使用 mul()axis=0:

df2.iloc[:,6:26].mul(df2["depreciation_rate"], axis=0)