@@ -7973,8 +7973,9 @@ def resample(
7973
7973
`DatetimeIndex`, `TimedeltaIndex` or `PeriodIndex`.
7974
7974
closed : {'right', 'left'}, default None
7975
7975
Which side of bin interval is closed. The default is 'left'
7976
- for all frequency offsets except for 'M', 'A', 'Q', 'BM',
7977
- 'BA', 'BQ', and 'W' which all have a default of 'right'.
7976
+ for all frequency offsets with forward resampling except for 'M',
7977
+ 'A', 'Q', 'BM', 'BA', 'BQ', and 'W' which all have a default of
7978
+ 'right'. When `Backward` set to be True, default is 'right'.
7978
7979
label : {'right', 'left'}, default None
7979
7980
Which bin edge label to label bucket with. The default is 'left'
7980
7981
for all frequency offsets except for 'M', 'A', 'Q', 'BM',
@@ -8007,7 +8008,7 @@ def resample(
8007
8008
level : str or int, optional
8008
8009
For a MultiIndex, level (name or number) to use for
8009
8010
resampling. `level` must be datetime-like.
8010
- origin : {'epoch', 'start', 'start_day'}, Timestamp or str, default 'start_day'
8011
+ origin : {'epoch', 'start', 'start_day', 'end', 'end_day' }, Timestamp or str, default 'start_day'
8011
8012
The timestamp on which to adjust the grouping. The timezone of origin
8012
8013
must match the timezone of the index.
8013
8014
If a timestamp is not used, these values are also supported:
@@ -8018,6 +8019,21 @@ def resample(
8018
8019
8019
8020
.. versionadded:: 1.1.0
8020
8021
8022
+ - 'end': `origin` is the last value of the timeseries
8023
+ - 'end_day': `origin` is the ceiling midnight of the last day
8024
+
8025
+ .. versionadded:: 1.2.0
8026
+
8027
+ backward : bool, default is None
8028
+ Resample on the given `origin` from a backward direction. True when
8029
+ `origin` is 'end' or 'end_day'. False when `origin` is 'start' or
8030
+ 'start_day'. Optional when using datetime `origin` , and default
8031
+ False. The resample result for a specified datetime stands for the
8032
+ group from time substract the given `freq` to time with a right
8033
+ `closed` setting by default.
8034
+
8035
+ .. versionadded:: 1.2.0
8036
+
8021
8037
offset : Timedelta or str, default is None
8022
8038
An offset timedelta added to the origin.
8023
8039
@@ -8297,6 +8313,28 @@ def resample(
8297
8313
2000-10-02 00:21:00 24
8298
8314
Freq: 17T, dtype: int64
8299
8315
8316
+ If you want to take the last timestamp as `origin` with a backward resample:
8317
+
8318
+ >>> ts.index.max()
8319
+ Timestamp('2000-10-02 00:26:00', freq='7T')
8320
+ >>> ts.groupby(pd.Grouper(freq='17min', origin='end')).sum()
8321
+ 2000-10-01 23:35:00 0
8322
+ 2000-10-01 23:52:00 18
8323
+ 2000-10-02 00:09:00 27
8324
+ 2000-10-02 00:26:00 63
8325
+ Freq: 17T, dtype: int32
8326
+
8327
+ You can also specify the backward origin:
8328
+
8329
+ >>> ts.groupby(pd.Grouper(freq='17min',
8330
+ origin='2000-10-02 00:30:00',
8331
+ backward=True)).sum()
8332
+ 2000-10-01 23:39:00 3
8333
+ 2000-10-01 23:56:00 15
8334
+ 2000-10-02 00:13:00 45
8335
+ 2000-10-02 00:30:00 45
8336
+ Freq: 17T, dtype: int32
8337
+
8300
8338
To replace the use of the deprecated `base` argument, you can now use `offset`,
8301
8339
in this example it is equivalent to have `base=2`:
8302
8340
0 commit comments