You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bins of the grouping are adjusted based on the beginning of the day of the time series starting point. This works well with frequencies that are multiples of a day (like `30D`) or that divide a day evenly (like `90s` or `1min`). This can create inconsistencies with some frequencies that do not meet this criteria. To change this behavior you can specify a fixed Timestamp with the argument ``origin``.
1797
+
1798
+
For example:
1799
+
1800
+
.. ipython:: python
1801
+
1802
+
start, end ='2000-10-01 23:30:00', '2000-10-02 00:30:00'
1803
+
middle ='2000-10-02 00:00:00'
1804
+
rng = pd.date_range(start, end, freq='7min')
1805
+
ts = pd.Series(np.arange(len(rng)) *3, index=rng)
1806
+
ts
1807
+
1808
+
Here we can see that, when using ``origin`` with its default value (``'start_day'``), the result after ``'2000-10-02 00:00:00'`` are not identical depending on the start of time series:
Here we can see that, when setting ``origin`` to ``'epoch'``, the result after ``'2000-10-02 00:00:00'`` are identical depending on the start of time series:
:class:`Grouper` and :class:`DataFrame.resample` now supports the arguments ``origin`` and ``offset``. It let the user control the timestamp on which to adjust the grouping. (:issue:`31809`)
161
+
162
+
The bins of the grouping are adjusted based on the beginning of the day of the time series starting point. This works well with frequencies that are multiples of a day (like `30D`) or that divides a day (like `90s` or `1min`). But it can create inconsistencies with some frequencies that do not meet this criteria. To change this behavior you can now specify a fixed timestamp with the argument ``origin``.
163
+
164
+
Two arguments are now deprecated (more information in the documentation of :class:`DataFrame.resample`):
165
+
166
+
- ``base`` should be replaced by ``offset``.
167
+
- ``loffset`` should be replaced by directly adding an offset to the index DataFrame after being resampled.
168
+
169
+
Small example of the use of ``origin``:
170
+
171
+
.. ipython:: python
172
+
173
+
start, end ='2000-10-01 23:30:00', '2000-10-02 00:30:00'
174
+
middle ='2000-10-02 00:00:00'
175
+
rng = pd.date_range(start, end, freq='7min')
176
+
ts = pd.Series(np.arange(len(rng)) *3, index=rng)
177
+
ts
178
+
179
+
Resample with the default behavior ``'start_day'`` (origin is ``2000-10-01 00:00:00``):
180
+
181
+
.. ipython:: python
182
+
183
+
ts.resample('17min').sum()
184
+
ts.resample('17min', origin='start_day').sum()
185
+
186
+
Resample using a fixed origin:
187
+
188
+
.. ipython:: python
189
+
190
+
ts.resample('17min', origin='epoch').sum()
191
+
ts.resample('17min', origin='2000-01-01').sum()
192
+
193
+
If needed you can adjust the bins with the argument ``offset`` (a Timedelta) that would be added to the default ``origin``.
194
+
195
+
For a full example, see: :ref:`timeseries.adjust-the-start-of-the-bins`.
0 commit comments