2 回答
TA贡献1799条经验 获得超8个赞
IIUC,那么你可以使用这个:
df[newCol] = df[oldCol].mul(numVal, axis=1)
df
输出:
a b c d e f alpha beta gamma
0 -0.725042 -0.756909 0.070109 0.850219 1.792450 1.324259 -1.450084 -3.784547 0.420656
1 -0.062379 -0.105332 -1.222571 -1.297675 -0.514850 0.610115 -0.124758 -0.526659 -7.335425
2 1.396269 -0.602535 0.033669 1.190688 0.335367 1.287264 2.792537 -3.012675 0.202014
3 0.303298 -2.016903 0.748448 0.317952 -0.319775 -1.023614 0.606595 -10.084517 4.490689
4 -0.469161 -2.133385 -0.488404 1.322836 0.560578 1.436018 -0.938321 -10.666927 -2.930423
5 -0.177657 -1.065320 -0.103551 0.406531 0.128109 0.387128 -0.355314 -5.326601 -0.621305
TA贡献1842条经验 获得超12个赞
您可以使用zip函数和简单的for循环来完成此操作:
In [24]: for i,j,k in list(zip(numVal, oldCol, newCol)):
...: df[k] = df[j] * i
...:
In [25]: df
Out[25]:
a b c d e f alpha beta gamma
0 0.737824 1.085417 1.369061 0.565950 -2.075468 -0.929977 1.475647 5.427085 8.214369
1 -1.337789 0.278580 -1.880562 0.082981 -0.487926 0.553878 -2.675578 1.392898 -11.283371
2 -0.711687 -0.698380 2.051574 -0.846402 -0.580580 0.031335 -1.423375 -3.491900 12.309442
3 0.239819 -1.092086 0.734303 -3.621612 -0.111699 1.675823 0.479638 -5.460428 4.405819
4 -0.320136 -0.406935 0.680605 -0.711390 0.176590 0.177886 -0.640271 -2.034674 4.083632
5 -0.174353 -0.750984 -0.057860 1.696935 -0.210906 2.786231 -0.348707 -3.754922 -0.347160
添加回答
举报