Skip to content

DOC: Add example for pandas.DataFrame.rolling() with on #50139

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

Merged
merged 5 commits into from
Dec 14, 2022
Merged
Changes from 4 commits
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
29 changes: 29 additions & 0 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,35 @@ class Window(BaseWindow):
2 2.958621
3 NaN
4 NaN

**on**

Rolling sum with a window length of 2 on specific columon.
Copy link
Member

Choose a reason for hiding this comment

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

2 days?


>>> df = pd.DataFrame({
... 'A': [pd.to_datetime('2020-01-01'),
... pd.to_datetime('2020-01-01'),
... pd.to_datetime('2020-01-02'),],
... 'B': [1, 2, 3], },
... index=pd.date_range('2020', periods=3))

>>> df
A B
2020-01-01 2020-01-01 1
2020-01-02 2020-01-01 2
2020-01-03 2020-01-02 3

>>> df['B'].rolling('2D').sum() # to avoid warning when sum on 'A'
2020-01-01 1.0
2020-01-02 3.0
2020-01-03 5.0
Freq: D, Name: B, dtype: float64

Copy link
Member

Choose a reason for hiding this comment

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

Seeing as you start with

Rolling sum with a window length of 2 on specific columon.

we can probably exclude this example. If someone tries running it locally, then can remove on= and see the difference, at which point it should be clear what it's done

>>> df.rolling('2D', on='A').sum() # value of 'B' differs from above
Copy link
Member

Choose a reason for hiding this comment

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

let's remove the comment

A B
2020-01-01 2020-01-01 1.0
2020-01-02 2020-01-01 3.0
2020-01-03 2020-01-02 6.0
"""

_attributes = [
Expand Down