熊猫遍历覆盖值

时间:2018-11-11 18:25:15

标签: pandas loops dataframe iteration

我试图使用iterrows作为处理框架的命令。

stocks2['Startpoint']=0
for index,row in stocks2.iterrows():
    if row['VOL']>4*row['avg'] and row['RET']< -0.02 :
        row['Startpoint']=1

我知道多次满足该条件,但是在这种情况下似乎并不能成功覆盖该值。

stocks2['Startpoint'].value_counts()

出[141]: 0 1588603 名称:起点,dtype:int64

1 个答案:

答案 0 :(得分:1)

无需循环,可以使用

stocks2['Startpoint']=((stocks2['VOL']>4*stocks2['ave'])&(stocks2['RET']<0.2)).astype(int)
相关问题