diff --git a/doc/source/computation.rst b/doc/source/computation.rst index 1414d2dd3c8dc..d727424750be5 100644 --- a/doc/source/computation.rst +++ b/doc/source/computation.rst @@ -214,6 +214,11 @@ computing common *window* or *rolling* statistics. Among these are count, sum, mean, median, correlation, variance, covariance, standard deviation, skewness, and kurtosis. +Starting in version 0.18.1, the ``rolling()`` and ``expanding()`` +functions can be used directly from DataFrameGroupBy objects, +see the :ref:`groupby docs `. + + .. note:: The API for window statistics is quite similar to the way one works with ``GroupBy`` objects, see the documentation :ref:`here ` diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst index c5a77770085d6..ff97775afc2e2 100644 --- a/doc/source/groupby.rst +++ b/doc/source/groupby.rst @@ -614,6 +614,54 @@ and that the transformed data contains no NAs. grouped.ffill() + +.. _groupby.transform.window_resample: + +New syntax to window and resample operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. versionadded:: 0.18.1 + +Working with the resample, expanding or rolling operations on the groupby +level used to require the application of helper functions. However, +now it is possible to use ``resample()``, ``expanding()`` and +``rolling()`` as methods on groupbys. + +The example below will apply the ``rolling()`` method on the samples of +the column B based on the groups of column A. + +.. ipython:: python + + df = pd.DataFrame({'A': [1] * 10 + [5] * 10, + 'B': np.arange(20)}) + df + + df.groupby('A').rolling(4).B.mean() + + +The ``expanding()`` method will accumulate a given operation +(``sum()`` in the example) for all the members of each particular +group. + +.. ipython:: python + + df.groupby('A').expanding().sum() + + +Suppose you want to use the ``resample()`` method to get a daily +frequency in each group of your dataframe and wish to complete the +missing values with the ``ffill()`` method. + +.. ipython:: python + + df = pd.DataFrame({'date': pd.date_range(start='2016-01-01', + periods=4, + freq='W'), + 'group': [1, 1, 2, 2], + 'val': [5, 6, 7, 8]}).set_index('date') + df + + df.groupby('group').resample('1D').ffill() + .. _groupby.filter: Filtration diff --git a/doc/source/timeseries.rst b/doc/source/timeseries.rst index 854de443ac5ee..9253124f7e8b2 100644 --- a/doc/source/timeseries.rst +++ b/doc/source/timeseries.rst @@ -1288,6 +1288,9 @@ limited to, financial applications. ``.resample()`` is a time-based groupby, followed by a reduction method on each of its groups. See some :ref:`cookbook examples ` for some advanced strategies +Starting in version 0.18.1, the ``resample()`` function can be used directly from +DataFrameGroupBy objects, see the :ref:`groupby docs `. + .. note:: ``.resample()`` is similar to using a ``.rolling()`` operation with a time-based offset, see a discussion :ref:`here `