[問題] for loop後將list存入dataframe
各位版大好,以下程式中有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]
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.125.195.36
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1558180977.A.82F.html
推
05/18 21:04,
6年前
, 1F
05/18 21:04, 1F
→
05/18 21:05,
6年前
, 2F
05/18 21:05, 2F
推
05/20 02:55,
6年前
, 3F
05/20 02:55, 3F
→
05/27 05:36,
6年前
, 4F
05/27 05:36, 4F
→
05/27 05:36,
6年前
, 5F
05/27 05:36, 5F
Python 近期熱門文章
PTT數位生活區 即時熱門文章