Home > Net >  pandas `rolling` does not know its own functions
pandas `rolling` does not know its own functions

Time:10-21

If I have a pandas series foo, foo.mad() computes the mean absolute deviation of foo. So, one might think that foo.rolling(10).mad() would compute the rolling mean absolution deviation, by analogy with, say foo.rolling(10).std(). But when I do that, I get an attribute error: 'Rolling' has no attribute 'mad'. Is there a canonical way to deal with it (for the particular function mad it is not too difficult to roll one's own, since it does something quite simple, but it seems morally wrong)

CodePudding user response:

For Series methods that don't yet have a corresponding rolling implementation, use rolling.apply, e.g.:

foo.rolling(10).apply(pd.Series.mad)
  • Related