Skip to content

Commit e17a7f8

Browse files
authored
DOC: Add example for pandas.DataFrame.rolling() with on (#50139)
* Add example for pandas.DataFrame.rolling() * Reduce two examples to one * a better exmple * a better layout
1 parent 113bdb3 commit e17a7f8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pandas/core/window/rolling.py

+23
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,29 @@ class Window(BaseWindow):
11101110
2 2.958621
11111111
3 NaN
11121112
4 NaN
1113+
1114+
**on**
1115+
1116+
Rolling sum with a window length of 2 days.
1117+
1118+
>>> df = pd.DataFrame({
1119+
... 'A': [pd.to_datetime('2020-01-01'),
1120+
... pd.to_datetime('2020-01-01'),
1121+
... pd.to_datetime('2020-01-02'),],
1122+
... 'B': [1, 2, 3], },
1123+
... index=pd.date_range('2020', periods=3))
1124+
1125+
>>> df
1126+
A B
1127+
2020-01-01 2020-01-01 1
1128+
2020-01-02 2020-01-01 2
1129+
2020-01-03 2020-01-02 3
1130+
1131+
>>> df.rolling('2D', on='A').sum()
1132+
A B
1133+
2020-01-01 2020-01-01 1.0
1134+
2020-01-02 2020-01-01 3.0
1135+
2020-01-03 2020-01-02 6.0
11131136
"""
11141137

11151138
_attributes = [

0 commit comments

Comments
 (0)