This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Is combining these 3 methods not possible?
I have a dataframe of different people and want to create a column that is a rolling average of just that person's last X data points. I keep getting various errors and haven't been able to find a stackoverflow or youtube video explaining how to do this/if its possible.
I've gotten errors ranging from you can't have a non-unique multi-index, to columns must be the same length as key, but am not sure why I'm getting those errors.
According to a stackoverflow post this should work:
df_all['3d_MA'] = df_all.groupby('Player Name')['Distance (km)'].rolling(3).mean().reset_index(drop=True)
But it gives me a column with the wrong numbers, plus the first 2 values for each person are not NaN which they should be since there isnt enough data points.
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...