我有这个数据框,我想用最后3场比赛中每个球员的平均分来完成最后一栏
data = {
'Player1' : ['John','Charles','Alexander','Michael','John','John','Michael','Alexander','Charles','Michael','John','Michael','Alexander'],
'Player2' : ['Charles','Alexander','Michael','John','Chales','Alexander','Alexander','Charles','John','Alexander','Charles','Charles','John'],
'P1 Points': [10,8,10,5,10,9,6,7,10,8,10,10,8],
'P2 Points': [6,10,7,10,7,10,10,10,7,10,7,6,10]
}
新列:
Date Player1 Player2 P1_Points P2_Points P1last3gamesPTs \
0 2019-12-21 John Charles 10 6 NaN
1 2019-12-21 Charles Alexander 8 10 NaN
2 2019-12-21 Alexander Michael 10 7 NaN
3 2019-12-21 Michael John 5 10 NaN
4 2019-12-22 John Chales 10 7 NaN
5 2019-12-22 John Alexander 9 10 NaN
6 2019-12-22 Michael Alexander 6 10 NaN
7 2019-12-22 Alexander Charles 7 10 NaN
8 2019-12-23 Charles John 10 7 NaN
9 2019-12-23 Michael Alexander 8 10 NaN
10 2019-12-23 John Charles 10 7 NaN
11 2019-12-23 Michael Charles 10 6 NaN
12 2019-12-24 Alexander John 8 10 NaN
P2last3gamesPTs
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 NaN
6 NaN
7 NaN
8 NaN
9 NaN
10 NaN
11 NaN
12 NaN
可能需要一些迭代,但我不知道怎么做,有人能帮我吗?你知道吗
你可以试试
关键是用^{} 堆栈,然后用} 返回两列
groupby.rolling
,最后用^{输出
熔融溶液
相关问题 更多 >
编程相关推荐