Skip to content

DOC: minor groupby and resampler improvements #19514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/source/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,8 @@ see :ref:`here <basics.pipe>`.
Combining ``.groupby`` and ``.pipe`` is often useful when you need to reuse
GroupBy objects.

For an example, imagine having a DataFrame with columns for stores, products,
revenue and sold quantity. We'd like to do a groupwise calculation of *prices*
As an example, imagine having a DataFrame with columns for stores, products,
revenue and quantity sold. We'd like to do a groupwise calculation of *prices*
(i.e. revenue/quantity) per store and per product. We could do this in a
multi-step operation, but expressing it in terms of piping can make the
code more readable. First we set the data:
Expand All @@ -1230,7 +1230,8 @@ code more readable. First we set the data:
import numpy as np
n = 1000
df = pd.DataFrame({'Store': np.random.choice(['Store_1', 'Store_2'], n),
'Product': np.random.choice(['Product_1', 'Product_2', 'Product_3'], n),
'Product': np.random.choice(['Product_1',
'Product_2'], n),
'Revenue': (np.random.random(n)*50+10).round(2),
'Quantity': np.random.randint(1, 10, size=n)})
df.head(2)
Expand Down
27 changes: 24 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5561,6 +5561,10 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
reduce the dimensionality of the return type if possible,
otherwise return a consistent type

Returns
-------
GroupBy object

Examples
--------
DataFrame results
Expand All @@ -5572,10 +5576,15 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,

>>> data.groupby(['col1', 'col2']).mean()

Returns
-------
GroupBy object
Notes
-----
See the `user guide
<http://pandas.pydata.org/pandas-docs/stable/groupby.html>`_ for more.

See also
--------
resample : Convenience method for frequency conversion and resampling
of time series.
"""
from pandas.core.groupby import groupby

Expand Down Expand Up @@ -5774,8 +5783,16 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,

.. versionadded:: 0.19.0

Returns
-------
Resampler object

Notes
-----
See the `user guide
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#resampling>`_
for more.

To learn more about the offset strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.

Expand Down Expand Up @@ -5941,6 +5958,10 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
a b c d
2000-01-01 00:00:00 0 6 12 18
2000-01-01 00:03:00 0 4 8 12

See also
--------
groupby : Group by mapping, function, label, or list of labels.
"""
from pandas.core.resample import (resample,
_maybe_process_deprecations)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
Notes
-----
See more `here
<http://pandas.pydata.org/pandas-docs/stable/groupby.html#pipe>`_
<http://pandas.pydata.org/pandas-docs/stable/groupby.html#piping-function-calls>`_

Examples
--------
Expand Down