datetime - python pandas: trying to reference data from another column's previous month end -
i trying create column in dataframe references value in column previous month end. this...
date sd sd.prevmo 02/29/00 0.0312 0.0312 03/01/00 0.0304 0.0312 03/02/00 0.0293 0.0312 03/03/00 0.0287 0.0312 03/28/00 0.0502 0.0312 03/29/00 0.0526 0.0312 03/30/00 0.0537 0.0312 03/31/00 0.0556 0.0556 04/03/00 0.0507 0.0556 04/04/00 0.0532 0.0556 04/05/00 0.0536 0.0556
the dateoffset functionality including bmonthend() seems have answer in must butchering that's not terribly complex.
df.ix[df.index.is_month_end==true, sd.prevmo] = df[sd] df.ix[df.index.is_month_end==false, sd.prevmo] = ???
has run before?
after set values is_month_end==true
df['sd']
, can full nas
ffill
methiod - forward fills values.
in [10]: df.ix[df.index.is_month_end==true, 'sd.prevmo'] = df['sd'] in [11]: df['sd.prevmo'].fillna(method='ffill') out[11]: date 2000-02-29 0.0312 2000-03-01 0.0312 2000-03-02 0.0312 2000-03-03 0.0312 2000-03-28 0.0312 2000-03-29 0.0312 2000-03-30 0.0312 2000-03-31 0.0556 2000-04-03 0.0556 2000-04-04 0.0556 2000-04-05 0.0556 name: sd.prevmo, dtype: float64
Comments
Post a Comment