Ask Your Question
2

How to obtain the date from the maximum rolling value?

asked 2023-06-30 15:42:08 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-30 15:53:02 +0000

scrum gravatar image

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}.")
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-30 15:42:08 +0000

Seen: 13 times

Last updated: Jun 30 '23