I have a pretty standard function that seems to create very odd responses; I thought I had figured out what was going on but now I'm not so sure.
essentially, I'd like to use the rolling function to create a simple rolling average of the two values before. When I do this directly it seems to pull values from elsewhere in the Frame for the first numbers, and when I do it in a loop I have no idea where its coming from.
Sample data:
player game_id game_order TOI_comp G_comp
A.J..GREER 2016020227 37 16.566667 0
2016020251 36 11.733333 0
2016020268 35 12.700000 0
2016020278 34 15.433333 0
2016020296 33 11.850000 0
player_avgs_base.sort_values(by=['player','game_order'],ascending=False, inplace=True)
avgtoi = player_avgs_base["TOI_comp"].rolling(2).mean().shift()
avgtoi
player game_id game_order
ZENON.KONOPKA 2013021047 2 NaN
A.J..GREER 2016020268 35 NaN
2016020278 34 9.308333
2016020296 33 14.066667
2017020134 32 13.641667
2017020149 31 10.108333
2017020165 30 7.175000
2017020194 29 6.100000
I would have expected more like
player game_id game_order
A.J..GREER 2016020251 36 NaN
2016020268 35 NaN
2016020278 34 12.22
2016020296 33 14.066667
2017020134 32 13.641667
2017020149 31 10.108333