Igor Rivin
Igor Rivin

Reputation: 4864

pandas `rolling` does not know its own functions

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)

Upvotes: 1

Views: 446

Answers (1)

tdy
tdy

Reputation: 41327

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

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

Upvotes: 2

Related Questions