Average Values In Last N Days Pandas
I've got a dataframe of golfers and their golf rounds in various tournaments (see dictionary of df head posted below). I need a fast way of computing, for each round the player pla
Solution 1:
This should work:
n = 10000
start_date = pd.to_datetime('today') - pd.Timedelta(n, unit='D')
df[df['Date'] >= start_date].groupby('Player')['Avg SG Player'].mean()
If you want to enter a start date and end date:
start_date = pd.to_datetime('2005-12-01')
end_date = pd.to_datetime('2015-12-01')
df[(df['Date'] >= start_date) & (df['Date'] <= end_date)].groupby('Player')['Avg SG Player'].mean()
Post a Comment for "Average Values In Last N Days Pandas"