I've got a pandas series in which each cell is a tuple. I'm trying to do a rolling().apply() on that series, and the function I'm trying to apply is never getting called. Here's a silly example that shows what I'm talking about:
>>> import pandas as pd
>>> pd.__version__
u'0.18.0'
>>> die = lambda x: 0/0
>>> s = pd.Series(zip(range(5), range(5)))
>>> s
0 (0, 0)
1 (1, 1)
2 (2, 2)
3 (3, 3)
4 (4, 4)
dtype: object
A simple apply
works as expected, in that the function is called:
>>> s.apply(die)
[...]
ZeroDivisionError: integer division or modulo by zero
But but a rolling().apply()
does nothing at all, and in particular the function that is supposed to be applied never gets called:
>>> s.rolling(2).apply(die)
0 (0, 0)
1 (1, 1)
2 (2, 2)
3 (3, 3)
4 (4, 4)
dtype: object
This is the simplest example that demonstrates what I'm talking about, but the same thing happens with sets & lists.
Why does this happen, and how can I do a rolling apply with a custom function on a series of collections?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…