如前所述,值得研究一下rolling_函数,这将意味着您周围没有那么多副本。
一个解决方案是CONCAT
转移系列在一起,使数据帧:
In [11]: pd.concat([s, s.shift(), s.shift(2)], axis=1)Out[11]: 0 1 21 5 NaN NaN2 4 5 NaN3 3 4 54 2 3 45 1 2 3In [12]: pd.concat([s, s.shift(), s.shift(2)], axis=1).dropna()Out[12]: 0 1 23 3 4 54 2 3 45 1 2 3
这样做比清单上的工作效率更高…



