1 | initial version |
To obtain the date from the maximum rolling value, follow these steps:
For example, let's say you have daily sales data and you want to find the date with the highest rolling 7-day sales total. You would:
Assuming your sales data is in a Pandas DataFrame called df
, your code might look something like this:
# Calculate rolling 7-day sum
df['rolling_7day_sales'] = df['sales'].rolling(window=7).sum()
# Find date with highest rolling 7-day sum
max_rolling_sum = df['rolling_7day_sales'].max()
max_rolling_date = df.loc[df['rolling_7day_sales'] == max_rolling_sum, 'date'].iloc[0]
# Output date with highest rolling 7-day sum
print(f"The date with the highest rolling 7-day sales total is {max_rolling_date}.")