-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Conversation
vangorade
commented
Jan 10, 2021
- closes DOC: example for doing a reversed rolling window #38627
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
@@ -198,6 +198,36 @@ from present information back to past information. This allows the rolling windo | |||
|
|||
df | |||
|
|||
.. _window.reverse_rolling_window: | |||
|
|||
Reverse rolling window |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
doc/source/user_guide/window.rst
Outdated
# Using slicing | ||
# apply the rolling aggregation and then flip the result. |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 👍
doc/source/user_guide/window.rst
Outdated
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 |
There was a problem hiding this comment.
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?
df.rolling(2, method="table", min_periods=0).apply(weighted_mean, raw=True, engine="numba") # noqa:E501 | ||
df.rolling(2, method="table", min_periods=0).apply( | ||
weighted_mean, raw=True, engine="numba" | ||
) # noqa:E501 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this noqa is no longer needed
@@ -132,13 +135,13 @@ time based index must be monotonic. | |||
|
|||
.. ipython:: python | |||
|
|||
times = ['2020-01-01', '2020-01-03', '2020-01-04', '2020-01-05', '2020-01-29'] | |||
times = ["2020-01-01", "2020-01-03", "2020-01-04", "2020-01-05", "2020-01-29"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer that you don't change the quoting as its non-essential to this change
).set_index("time") | ||
df | ||
|
||
df1 = df[::-1].rolling("2s").sum()[::-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call this reversed_df
or similar
df1 = df[::-1].rolling("2s").sum()[::-1] | ||
df1 | ||
|
||
Or we can also do it using FixedForwardWindowIndexer which basically Creates window boundaries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the refernce to this, something like :meth:`api.indexers.FixedForwardWindowIndexer`
|
||
.. ipython:: python | ||
|
||
df = pd.DataFrame( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to repeat this
|
||
indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=2) | ||
|
||
df2 = df.rolling(window=indexer, min_periods=1).sum() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name as above
@@ -280,11 +330,23 @@ conditions. In these cases it can be useful to perform forward-looking rolling w | |||
This :func:`BaseIndexer <pandas.api.indexers.BaseIndexer>` subclass implements a closed fixed-width | |||
forward-looking rolling window, and we can use it as follows: | |||
|
|||
.. ipython:: ipython | |||
.. ipython:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having this here I woul dmove the example from above here. no reason to have this in 2 places and this is the best one.
can you merge master and update |
@vangorade can you merge master and update |
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
Going to close this PR due to lack of activity. Let us know if you'd like to continue working on it. |
File is copied from @vangorade last changes in pull request (pandas-dev#39091): pandas-dev#39091 Fixed typo to pass pre-commit codespell hook.
From pull request (pandas-dev#39091): pandas-dev#39091 - remove noqa - change line back to single quotes - rename df1 to reversed_df
From pull request (pandas-dev#39091): pandas-dev#39091 - remove repeated df initialization in code example - rename df2 to reversed_df
…andas-dev#38627). Move code example as suggested in pull request (pandas-dev#39091): pandas-dev#39091 Compiled document to check it looked fine by running: python make.py --single user_guide/window.rst
* DOC: Add examples to do reversed rolling window (#38627). File is copied from @vangorade last changes in pull request (#39091): #39091 Fixed typo to pass pre-commit codespell hook. * DOC: Add some suggested changes. From pull request (#39091): #39091 - remove noqa - change line back to single quotes - rename df1 to reversed_df * DOC: Add reference to FixedForwardWindowIndexer. * DOC: Add more suggested changes. From pull request (#39091): #39091 - remove repeated df initialization in code example - rename df2 to reversed_df * DOC: Add suggested changes to reverse rolling window code examples (#38627). Move code example as suggested in pull request (#39091): #39091 Compiled document to check it looked fine by running: python make.py --single user_guide/window.rst * DOC: Revert more double quotes to single quotes. Unecessary changes. * DOC: Change binary window description to match master branch. Description was not modified after fetching and merging, so pasted from master branch: https://github.com/pandas-dev/pandas/blob/master/doc/source/user_guide/window.rst * DOC: Change exponentially weighted mean formula to one in master branch. Since fetching and merging didn't modify this line. * DOC: Replace window.rst with file from pandas-dev master branch. To only add reverse rolling window section and avoid any unwanted changes. * DOC: Add section with reverse rolling window example. * DOC: Add section markup. Forgot to add. * DOC: Delete the same code example. FixedForwaredWindowIndexer example is same as the one above the added section. * DOC: Remove section and first sentence. Modify sentence slightly to show this example should output same result. * DOC: Remove unecessary words. Coding is already in Python.
* DOC: Add examples to do reversed rolling window (pandas-dev#38627). File is copied from @vangorade last changes in pull request (pandas-dev#39091): pandas-dev#39091 Fixed typo to pass pre-commit codespell hook. * DOC: Add some suggested changes. From pull request (pandas-dev#39091): pandas-dev#39091 - remove noqa - change line back to single quotes - rename df1 to reversed_df * DOC: Add reference to FixedForwardWindowIndexer. * DOC: Add more suggested changes. From pull request (pandas-dev#39091): pandas-dev#39091 - remove repeated df initialization in code example - rename df2 to reversed_df * DOC: Add suggested changes to reverse rolling window code examples (pandas-dev#38627). Move code example as suggested in pull request (pandas-dev#39091): pandas-dev#39091 Compiled document to check it looked fine by running: python make.py --single user_guide/window.rst * DOC: Revert more double quotes to single quotes. Unecessary changes. * DOC: Change binary window description to match master branch. Description was not modified after fetching and merging, so pasted from master branch: https://github.com/pandas-dev/pandas/blob/master/doc/source/user_guide/window.rst * DOC: Change exponentially weighted mean formula to one in master branch. Since fetching and merging didn't modify this line. * DOC: Replace window.rst with file from pandas-dev master branch. To only add reverse rolling window section and avoid any unwanted changes. * DOC: Add section with reverse rolling window example. * DOC: Add section markup. Forgot to add. * DOC: Delete the same code example. FixedForwaredWindowIndexer example is same as the one above the added section. * DOC: Remove section and first sentence. Modify sentence slightly to show this example should output same result. * DOC: Remove unecessary words. Coding is already in Python.