我有两个DataFrame,我需要做以下计算: 我想通过将上面的100乘以值pct.loc ['20151216']来计算twr.loc ['20151215']。这应该分别对每个单元格进行,然后继续进行下一行。这是我尝试过的不起作用的地方:
for eachdate in range(1, len(daterange)):
date1_lbl = TWRR.index[eachdate]
date2_lbl = TWRR.index[eachdate+1]
TWRR.loc[date2_lbl] = TWRR.loc[date1_lbl] * (1 + pct_change.loc[date2_lbl])
print pct
a b c d
Date
2015-12-15 NaN NaN NaN NaN
2015-12-16 -0.006232 -0.011392 -0.010945 -0.010373
2015-12-17 -0.011626 -0.014725 -0.016674 -0.006613
2015-12-18 -0.012519 -0.015595 -0.014799 -0.003768
print twr
a b c d
2015-12-15 100 100 100 100
2015-12-16 NaN NaN NaN NaN
2015-12-17 NaN NaN NaN NaN
2015-12-18 NaN NaN NaN NaN
所以它应该首先填写'2015-12-16',如下:
2015-12-16 99.99376 98.8608 98.90550 0.989627
然后它应该通过使用先前计算的行来计算'2015-12-17'......我似乎无法弄明白。谢谢你的帮助!