Python:用于添加数据帧时的循环迭代

我有一个不同返回值的dataframe,如下所示:

0.2  -0.1  0.03  0.01
0.02  0.1  -0.1  -0.2
0.05  0.06  0.07 -0.07
0.03 -0.04 -0.04 -0.03

我有一个单独的dataframe,索引返回只在一列中:

0.01
0.015
-0.01
-0.02

我想做的基本上是将索引返回数据帧的每个行值与股票返回数据帧中每列的每个值相加(+)。

期望的结果如下所示:

0.21  -0.09
0.035  0.115
0.04   0.05
0.01  -0.06 etc etc

例如,通常在Matlab中,for循环会非常简单,但在python中,索引是让我感到困惑的地方。我尝试了一个简单的for循环:

for i, j in df_stock_returns.iterrows():
    df_new = df_stock_returns[i, j] + df_index_reuturns[j] 

但这并不是真的有效,任何帮助都是非常感谢的!

转载请注明出处:http://www.starkdigitech.com/article/20230526/1481636.html