Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In [11]: df
- Out[11]:
- A B
- 2000-01-01 -0.182994 0
- 2000-01-02 1.290203 0
- 2000-01-03 0.245229 0
- 2000-01-08 -1.230742 0
- 2000-01-09 0.534939 0
- 2000-01-10 1.324027 0
- for idx,row in df.iterrows():
- if df["A"][idx]<-1:
- df["B"][idx] = -1
- elif df["A"][idx]>1:
- df["B"][idx] = 1
- else:
- df["B"][idx] = df["B"][idx-1]
- In [38]: df = DataFrame(randn(10,2),columns=list('AB'))
- In [39]: df['B'] = np.nan
- In [40]: df.loc[df.A<-1,'B'] = -1
- In [41]: df.loc[df.A>1,'B'] = 1
- In [42]: df.ffill()
- Out[42]:
- A B
- 0 -1.186808 -1
- 1 -0.095587 -1
- 2 -1.921372 -1
- 3 -0.772836 -1
- 4 0.016883 -1
- 5 0.350778 -1
- 6 0.165055 -1
- 7 1.101561 1
- 8 -0.346786 1
- 9 -0.186263 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement