Skip to content

Commit b492293

Browse files
committed
fix doc
1 parent 0cff41e commit b492293

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

doc/source/user_guide/timeseries.rst

+15-13
Original file line numberDiff line numberDiff line change
@@ -1888,31 +1888,39 @@ Those two examples are equivalent for this time series:
18881888
18891889
Note the use of ``'start'`` for ``origin`` on the last example. In that case, ``origin`` will be set to the first value of the timeseries.
18901890

1891+
.. _timeseries.backward-resample:
1892+
18911893
Backward resample
18921894
~~~~~~~~~~~~~~~~~
18931895

18941896
.. versionadded:: 1.2.0
18951897

1896-
``origin`` can not only make a foreward resample, namely grouping from the starting point with the given ``freq`` , but is also able to implement the backward resample. This method allows users to control bins of the grouping from the given origin with a backward direction. (:issue:`37804`)
1898+
``origin`` can not only make a foreward resample, namely grouping from the starting point with the given ``freq``, but is also able to implement the backward resample. This method allows users to control bins of the grouping from the given origin with a backward direction. (:issue:`37804`)
18971899

18981900
.. ipython:: python
18991901
19001902
start, end = "2000-10-01 23:30:00", "2000-10-02 00:26:00"
1901-
rng = date_range(start, end, freq="7min")
1902-
ts = Series(np.arange(len(rng)) * 3, index=rng)
1903+
rng = pd.date_range(start, end, freq="7min")
1904+
ts = pd.Series(np.arange(len(rng)) * 3, index=rng)
19031905
1904-
Setting ``offset='end'`` means using the max ``Timestamp`` as the ``origin`` with ``backward=True`` .
1906+
Setting ``offset='end'`` means using the max ``Timestamp`` as the ``origin`` with ``backward=True``.
19051907

19061908
ts.index.max()
19071909
ts.resample("17min", origin="end").sum()
19081910

1909-
Setting ``offset='end'`` means using the ceiling midnight of the max ``Timestamp`` as the ``origin`` with ``backward=True`` .
1911+
The forward resample output stands for the grouping result from current datetimeindex to the next one with ``closed=left`` by default. In contrast, the backward resample output stands for the grouping result from former datetimeindex to the current one with ``closed=right`` by default. If you want to change this, ``closed=left`` is available.
19101912

19111913
.. ipython:: python
19121914
1913-
ts.resample("17min", origin="end").sum()
1915+
ts.resample("17min", closed="left", origin="end").sum()
1916+
1917+
Setting ``offset='end_day'`` means using the ceiling midnight of the max ``Timestamp`` as the ``origin`` with ``backward=True``.
1918+
1919+
.. ipython:: python
19141920
1915-
If you want to make the backward resample from a Timestamp-like ``origin`` , ``backward=True`` should be set.
1921+
ts.resample("17min", origin="end_day").sum()
1922+
1923+
If you want to make the backward resample from a Timestamp-like ``origin``, ``backward=True`` should be set.
19161924

19171925
.. ipython:: python
19181926
@@ -1926,12 +1934,6 @@ You can implement ``offset='end_day'`` in the following method equivalently.
19261934
end_day_origin
19271935
ts.resample("17min", origin=end_day_origin, backward=True).sum()
19281936
1929-
By defualt, backward resample uses ``closed=right`` while ``closed=left`` is also available.
1930-
1931-
.. ipython:: python
1932-
1933-
ts.resample("17min", closed="left", origin="end").sum()
1934-
19351937
.. _timeseries.periods:
19361938

19371939
Time span representation

doc/source/whatsnew/v1.2.0.rst

+9-21
Original file line numberDiff line numberDiff line change
@@ -206,47 +206,35 @@ level-by-level basis.
206206

207207
.. _whatsnew_120.backward_resample:
208208

209-
Backward resample
209+
Backward resample
210210
^^^^^^^^^^^^^^^^^
211211

212-
:class:`Grouper` and :meth:`DataFrame.resample` now support the argument ``backward`` . ``'end'`` and ``'end_day'`` are available in argument ``offset`` . Backward resample allows users to control bins of the grouping from the given origin with a backward direction. (:issue:`37804`)
212+
:class:`Grouper` and :meth:`DataFrame.resample` now support the argument ``backward``. ``'end'`` and ``'end_day'`` are available in argument ``offset``. Backward resample allows users to control bins of the grouping from the given origin with a backward direction. (:issue:`37804`)
213213

214214
.. ipython:: python
215215
216216
start, end = "2000-10-01 23:30:00", "2000-10-02 00:26:00"
217-
rng = date_range(start, end, freq="7min")
218-
ts = Series(np.arange(len(rng)) * 3, index=rng)
217+
rng = pd.date_range(start, end, freq="7min")
218+
ts = pd.Series(np.arange(len(rng)) * 3, index=rng)
219219
220-
Setting ``offset='end'`` means using the max ``Timestamp`` as the ``origin`` with ``backward=True`` .
220+
Setting ``offset='end'`` means using the max ``Timestamp`` as the ``origin`` with ``backward=True``.
221221

222222
ts.index.max()
223223
ts.resample("17min", origin="end").sum()
224224

225-
Setting ``offset='end'`` means using the ceiling midnight of the max ``Timestamp`` as the ``origin`` with ``backward=True`` .
225+
Setting ``offset='end_day'`` means using the ceiling midnight of the max ``Timestamp`` as the ``origin`` with ``backward=True``.
226226

227227
.. ipython:: python
228228
229-
ts.resample("17min", origin="end").sum()
229+
ts.resample("17min", origin="end_day").sum()
230230
231-
If you want to make the backward resample from a Timestamp-like ``origin`` , ``backward=True`` should be set.
231+
If you want to make the backward resample from a Timestamp-like ``origin``, ``backward=True`` should be set.
232232

233233
.. ipython:: python
234234
235235
ts.resample("17min", origin="2000-10-02 00:40:00", backward=True).sum()
236236
237-
You can implement ``offset='end_day'`` in the following method equivalently.
238-
239-
.. ipython:: python
240-
241-
end_day_origin = ts.index.max().ceil("D")
242-
end_day_origin
243-
ts.resample("17min", origin=end_day_origin, backward=True).sum()
244-
245-
By defualt, backward resample uses ``closed=right`` while ``closed=left`` is also available.
246-
247-
.. ipython:: python
248-
249-
ts.resample("17min", closed="left", origin="end").sum()
237+
For details, see: :ref:`timeseries.backward-resample`.
250238

251239
.. _whatsnew_120.groupby_ewm:
252240

0 commit comments

Comments
 (0)