#๐Ÿ”’ pandas df rolling window with step size?

11 messages ยท Page 1 of 1 (latest)

twilit barn
#

Hello. My datetimeindex has a delta of 15 seconds and no gaps between start_dt and end_dt. For each timestamp, I am trying to find the max value in a 7 day past window for that exact timestamp. i.e. for dt 2024-04-02 00:00:00, I want to look at the same timestamp 00:00:00 but on 2024-04-01, 2024-03-31, ...

But it seems the step parameter in the df method .rolling() is rather unintuitive wherein it is fully skipping over rows by the step size, rather than making sliding window steps by that step size for each row. For step=2, the rows halve in number for example. Here's what I'm working with currently, please let me know what I can do.

df["val"].rolling(window=7*4*60*24, step=4*60*24, min_periods=1)
where 4 * 60 * 24 skips 1 day (15 second delta * 4 (== 1 minute) * 60 * 24)
I've already tried the other intuitive variation, window=7

Thanks in advance.

thorny tundraBOT
#

@twilit barn

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

steady gust
#

have you tried using a timedelta object of 7 days?

#

you might even be able to do .rolling('7D') for 7 day rolling window according to the docs

mellow hill
twilit barn
twilit barn
twilit barn
#

so 7 values for that timestamp over the last 7 days, even though there are timestamps at 15 second intervals

thorny tundraBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.