lundi 11 juillet 2016

Pandas Groupby TimeGrouper and apply


As per this question. This groupby works when applied to my df for a pd.rolling_mean column as follows:

data['maFast']=data['Last'].groupby(pd.TimeGrouper('d'))
                           .apply(pd.rolling_mean,center=False,win‌​dow=10) 

How do I apply the same groupby logic to another element of my df which contains pd.rolling_std and pd.rolling_mean:

data['maSlow_std'] = pd.rolling_mean(data['Last'], window=60) + 
                  2* pd.rolling_std(data['Last'], 20, min_periods=20) 

Aucun commentaire:

Enregistrer un commentaire