作者allenlenten (...)
看板Python
标题[问题] pandas 回圈运算
时间Thu Jun 22 16:28:52 2017
大家好 我想要问怎麽改变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://webptt.com/cn.aspx?n=bbs/Python/M.1498120134.A.E6A.html
1F:推 Scinfaxi: acc的index是0开始的依序整数就可以吧? 06/22 20:53
2F:→ Scinfaxi: 如果不是是否改成for mo in range(len(acc.index))? 06/22 20:55
3F:推 Django: 是说acc = df[df['成交时间']>=90500] <--有这种语法@@? 06/22 21:30
4F:→ allenlenten: 这是我取得条件的index。他不是从0开始 有时候index 06/22 21:55
5F:→ allenlenten: 也不是斗连续 可能有跳号 06/22 21:55
6F:推 ntumath: iloc的用法就是把需要格子的座标当作参数,所以你要先取 06/23 04:44
7F:→ ntumath: 得你要的index名字的座标。用看看get_loc吧 06/23 04:44
8F:推 HenryLiKing: 回gjango 有喔 中间那段会回传一堆T和F 然後是T 06/23 08:52
9F:→ HenryLiKing: 的就会被抓到喔 06/23 08:52
10F:→ Django: 嗯~~~df的型态是什麽啊 我本来以为是dict 06/23 09:58
11F:推 max533: 回楼上,df应该是pandas的物件Dataframe 06/24 20:22