np.random.seed([3, 14])
df = pd.DataFrame(np.random.randn(5, 3), columns=list('ABC'))
df
A B C
0 -0.602923 -0.402655 0.302329
1 -0.524349 0.543843 0.013135
2 -0.326498 1.385076 -0.132454
3 -0.407863 1.302895 -0.604236
4 -0.243362 -0.211261 -2.056621
What is the fastest way to compute df.A * 1 + df.B * 2 + df.C * 3
?
Essentially, I want, for this dataframe:
0 -0.501247
1 0.602741
2 2.046290
3 0.385219
4 -6.835748
The answer cannot be df.A * 1 + df.B * 2 + df.C * 3
since the number of columns must not be hardcoded. So, I'd want to compute df.iloc[:, 0] * 1 + df.iloc[:, 1] * 2, ....
somehow.
I'd be interested in any numba
solutions out there too!