2016-08-20 57 views
0

我想创建一个if/then语句,通过我在熊猫表中的每一行,但我无法弄清楚如何去做。熊猫如果语句迭代遍历行

entry_price = df['0VWAP'] 
low_price = df['0L'] 
df["stopped"] = low_price < .95*entry_price 
for row in df: 
    if df['stopped'].bool == True: 
     print 'Stopped out' 
    else: 
     print 'Open' 

当我运行这段代码时,它会打印所有内容,当它应该是两者的混合时。

+0

你遍历'row',但没有检查它在所有的你的'if'语句。尝试像'if row.stopped:'。 –

回答

0

如果你只想打印'Stopped out''Open'if语句,那么你可以只是简单的做到这一点:

for row in df["stopped"]: 
    if row > 0: 
     print ('Stopped out') 
    else: 
     print ('Open')