假设您有一些代码:
def test(x):
# some function that operates on a list of lists
# and returns a value
import pandas as pd
data = pd.Series([1,2,3], [4,5,6], [7,8,9])
x = data.rolling(2).apply(lambda x: test(x))
print(x)
当上面的代码运行时,x
总是等于data
. 就好像滚动功能从未应用过。
如何将这样的滚动(或扩展)功能应用于 Pandas 系列?