<p>你可以试试</p>
<pre class="lang-py prettyprint-override"><code>>>> df['P2last3gamesPTs'] = df['P2 Points'].rolling(window=3).mean()
>>> df['P1last3gamesPTs'] = df['P1 Points'].rolling(window=3).mean()
>>> df
Player1 Player2 P1 Points P2 Points P2last3gamesPTs P1last3gamesPTs
0 John Charles 10 6 NaN NaN
1 Charles Alexander 8 10 NaN NaN
2 Alexander Michael 10 7 7.666667 9.333333
3 Michael John 5 10 9.000000 7.666667
4 John Chales 10 7 8.000000 8.333333
5 John Alexander 9 10 9.000000 8.000000
6 Michael Alexander 6 10 9.000000 8.333333
7 Alexander Charles 7 10 10.000000 7.333333
8 Charles John 10 7 9.000000 7.666667
9 Michael Alexander 8 10 9.000000 8.333333
10 John Charles 10 7 8.000000 9.333333
11 Michael Charles 10 6 7.666667 9.333333
12 Alexander John 8 10 7.666667 9.333333
</code></pre>