-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: add time-window capability to .rolling #13513
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,17 @@ | |
v0.19.0 (August ??, 2016) | ||
------------------------- | ||
|
||
This is a major release from 0.18.2 and includes a small number of API changes, several new features, | ||
This is a major release from 0.18.1 and includes a small number of API changes, several new features, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jorisvandenbossche slight changes need here (which are in master). done here i think is fine. |
||
enhancements, and performance improvements along with a large number of bug fixes. We recommend that all | ||
users upgrade to this version. | ||
|
||
Highlights include: | ||
|
||
- :func:`merge_asof` for asof-style time-series joining, see :ref:`here <whatsnew_0190.enhancements.asof_merge>` | ||
- ``.rolling()`` are now time-series aware, see :ref:`here <whatsnew_0190.enhancements.rolling_ts>` | ||
- pandas development api, see :ref:`here <whatsnew_0190.dev_api>` | ||
|
||
.. contents:: What's new in v0.18.2 | ||
.. contents:: What's new in v0.19.0 | ||
:local: | ||
:backlinks: none | ||
|
||
|
@@ -131,6 +132,64 @@ that forward filling happens automatically taking the most recent non-NaN value. | |
This returns a merged DataFrame with the entries in the same order as the original left | ||
passed DataFrame (``trades`` in this case), with the fields of the ``quotes`` merged. | ||
|
||
.. _whatsnew_0190.enhancements.rolling_ts: | ||
|
||
``.rolling()`` are now time-series aware | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
``.rolling()`` objects are now time-series aware and can accept a time-series offset (or convertible) for the ``window`` argument (:issue:`13327`, :issue:`12995`) | ||
See the full documentation :ref:`here <stats.moments.ts>`. | ||
|
||
.. ipython:: python | ||
|
||
dft = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}, | ||
index=pd.date_range('20130101 09:00:00', periods=5, freq='s')) | ||
dft | ||
|
||
This is a regular frequency index. Using an integer window parameter works to roll along the window frequency. | ||
|
||
.. ipython:: python | ||
|
||
dft.rolling(2).sum() | ||
dft.rolling(2, min_periods=1).sum() | ||
|
||
Specifying an offset allows a more intuitive specification of the rolling frequency. | ||
|
||
.. ipython:: python | ||
|
||
dft.rolling('2s').sum() | ||
|
||
Using a non-regular, but still monotonic index, rolling with an integer window does not impart any special calculation. | ||
|
||
.. ipython:: python | ||
|
||
|
||
dft = DataFrame({'B': [0, 1, 2, np.nan, 4]}, | ||
index = pd.Index([pd.Timestamp('20130101 09:00:00'), | ||
pd.Timestamp('20130101 09:00:02'), | ||
pd.Timestamp('20130101 09:00:03'), | ||
pd.Timestamp('20130101 09:00:05'), | ||
pd.Timestamp('20130101 09:00:06')], | ||
name='foo')) | ||
|
||
dft | ||
dft.rolling(2).sum() | ||
|
||
Using the time-specification generates variable windows for this sparse data. | ||
|
||
.. ipython:: python | ||
|
||
dft.rolling('2s').sum() | ||
|
||
Furthermore, we now allow an optional ``on`` parameter to specify a column (rather than the | ||
default of the index) in a DataFrame. | ||
|
||
.. ipython:: python | ||
|
||
dft = dft.reset_index() | ||
dft | ||
dft.rolling('2s', on='foo').sum() | ||
|
||
.. _whatsnew_0190.enhancements.read_csv_dupe_col_names_support: | ||
|
||
:func:`read_csv` has improved support for duplicate column names | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Code examples aside, from this description it isn't precisely clear what the time window does. Essentially we need to distinguish this clearly from
resample
(which has its own complexities with anchored vs non-anchored time offsets).Perhaps something like: "For each time point, includes all preceding values occurring within the indicated time delta." If it confuses people we can always create a diagram (for example: I will probably include this in the 2nd ed of my book and almost certainly create a diagram to make it clear).