【发布时间】:2021-12-26 01:02:28
【问题描述】:
我有这个数据框:
| Date | Position | TrainerID | Win% |
|---|---|---|---|
| 2017-09-03 | 4 | 1788 | 0 (0 wins, 1 race) |
| 2017-09-16 | 5 | 1788 | 0 (0 wins, 2 races) |
| 2017-10-14 | 1 | 1788 | 33 (1 win, 3 races) |
我想在Win% 列的每一行上计算过去 1000 天比赛的获胜百分比,如上所述。
我尝试过这样的事情:
def compute_winning_percentage(a, b):
return (a / b)*100
featured_data['Percentage win of trainer in the last 1000 days'] = featured_data.groupby('TrainerID').apply(
compute_winning_percentage(len(featured_data.loc[featured_data.Position == 1]),
featured_data[featured_data.Position].cumcount()))
但我收到一个错误,我不知道如何插入 过去 1000 天部分。
我该怎么做?
【问题讨论】: