各位版大好,以下程式中有3个for循环,目的势将i, j, k的值写入一dataframe df2,
不过运算结果一直出现"list index out of range"的错误讯息
不知道有没有什么方式可以解决?
又或者有其他方式可以达到预期的结果? 再麻烦各位大大解惑,谢谢!
预期达到的结果如下:
[[0, 50, 125, 100, 200, 300],
[0, 50, 250, 100, 200, 300],
[50, 100, 125, 100, 200, 300],
[50, 100, 250, 100, 200, 300]]
程式内容如下:
percentile_gap = 50
before_gap = 125
behind_gap = 100
before_max = before_gap*2
df2 = pd.DataFrame({'Lbound':[], 'Ubound':[], 'before_X_days':[]})
for i in range(0, 100-percentile_gap+1, percentile_gap):
correlation = []
correlation.append ( i )
correlation.append ( i + percentile_gap )
for j in range(125, before_max+1, before_gap):
correlation.append ( j )
for k in range(100, 300+1, behind_gap):
df2['+'+str(k)+' days'] = df2['Lbound']
correlation.append ( k )
df2.iloc[len(df2)] = [i][j][correlation]