0

I tried to use iterrows as a command to deal with the frame.

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

I know that the condition is met several times, but it does not seem to overwrite successfully the value in that case.

stocks2['Startpoint'].value_counts()

Out[141]: 0 1588603 Name: Startpoint, dtype: int64

1
  • because .iterows returns an iterator over pd.Series objects representing the rows of your data-frame, but mutating those pd.Series objects will not affect the original pd.DataFrame Commented Nov 11, 2018 at 18:34

1 Answer 1

1

No need for loop , You can do with

stocks2['Startpoint']=((stocks2['VOL']>4*stocks2['ave'])&(stocks2['RET']<0.2)).astype(int)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.