Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To obtain the date from the maximum rolling value, follow these steps:

  1. Calculate the rolling values for your data using a rolling window function such as rolling sum or rolling average.
  2. Find the maximum value in your rolling values.
  3. Identify the date or time period associated with the maximum rolling value. This will depend on how you have labeled your data.
  4. Output the date or time period for the maximum rolling value.

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:

  1. Calculate the rolling 7-day sum for your sales data.
  2. Find the maximum rolling 7-day sum.
  3. Identify the date associated with the maximum rolling 7-day sum.
  4. Output the date for the maximum rolling 7-day sum.

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}.")