看板 Python 關於我們 聯絡資訊
大家好 我想要問怎麼改變FOR 迴圈的起始和終值 比如說 我現有一個DF讀進來,然後 acc = df[df['成交時間']>=90500] for mo in acc.index: if df.iloc[mo,8] > 200: buy = df.iloc[more+1,4] out = 0 for mo in accumulate.index: while out < -200: out = out + df.iloc[mo+1,'vol'] 我想要判斷df.iloc[mo,8] > 200 後買進 然後之前的加總的值小於200賣出 我以為mo 可以連貫的.好像不是這樣 要如何只做一次這個index就好 我要怎麼控制這個迴圈的起始值呢? 或是有更好的解法 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.21.123.187 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1498120134.A.E6A.html
Scinfaxi: acc的index是0開始的依序整數就可以吧? 06/22 20:53
Scinfaxi: 如果不是是否改成for mo in range(len(acc.index))? 06/22 20:55
Django: 是說acc = df[df['成交時間']>=90500] <--有這種語法@@? 06/22 21:30
allenlenten: 這是我取得條件的index。他不是從0開始 有時候index 06/22 21:55
allenlenten: 也不是斗連續 可能有跳號 06/22 21:55
ntumath: iloc的用法就是把需要格子的座標當作參數,所以你要先取 06/23 04:44
ntumath: 得你要的index名字的座標。用看看get_loc吧 06/23 04:44
HenryLiKing: 回gjango 有喔 中間那段會回傳一堆T和F 然後是T 06/23 08:52
HenryLiKing: 的就會被抓到喔 06/23 08:52
Django: 嗯~~~df的型態是什麼啊 我本來以為是dict 06/23 09:58
max533: 回樓上,df應該是pandas的物件Dataframe 06/24 20:22