Skip to content

DOC: Added reverse rolling window examples #39091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions doc/source/user_guide/window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,36 @@ from present information back to past information. This allows the rolling windo

df

.. _window.reverse_rolling_window:

Reverse rolling window
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just add this as an example of using the FixedForwardWindowIndexer in the Custom window rolling section below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late reply. Sure i will add it.

~~~~~~~~~~~~~~~~~~~~~~

Get the window of a rolling function to look forward.

Examples:

.. ipython:: python

# Using slicing
# apply the rolling aggregation and then flip the result.
Copy link
Member

@MarcoGorelli MarcoGorelli Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at other examples from this document, descriptions are typically outside the code blocks (rather than inside them as comments)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Would be better if this description was a paragraph before the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

df = pd.DataFrame(data=[[pd.Timestamp('2018-01-01 00:00:00'), 100],
[pd.Timestamp('2018-01-01 00:00:01'), 101],
[pd.Timestamp('2018-01-01 00:00:03'), 103],
[pd.Timestamp('2018-01-01 00:00:04'), 111]],
columns=['time', 'value']).set_index('time')
df
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you apply the black formatter to this code block?


df1 = df[::-1].rolling('2s').sum()[::-1]
df1

# Using FixedForwardWindowIndexer
# Creates window boundaries for fixed-length windows that include the current row.
indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=2)

df2 = df.rolling(window=indexer, min_periods=1).sum()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name as above

df2


.. _window.custom_rolling_window:

Expand Down