我有两个数据帧,即share和Log_Returns。我想将份额的第一位数乘以Log_Returns的第一列。第二列的第二位数,依此类推。
shares
0
0 0.319297
1 99.680703
Log_return
HIGH MID
0 -1.998061 -1.991331
1 -0.014573 -1.981635
2 -2.015117 -1.978619
3 0.028488 -2.000455
我尝试了以下代码,但获得了串行输出。
for j in range(Log_return.shape[1]):
i = j
for k in range(len(Log_return)):
print(shares.iloc[i, 0] * Log_return.iloc[k, j])
-0.6379746350243671
-0.004652966683445539
-0.6434205307519527
0.009096189190505598
-198.49724749816215
-197.53080296760479
-197.23014837824016
-199.40677745293362
I want someone to help me for finding this results.
Log_return
HIGH MID
B -0.637975 -198.497247
C -0.004653 -197.530803
D -0.643421 -197.230148
E 0.009096 -199.406777
答案 0 :(得分:0)
使用numpy:
import numpy as np
np.multiply(log_return, shares.T)
应提供所需的输出。