Skip to content

DOC: fix flake8 issue in groupby.rst #24363

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
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
38 changes: 28 additions & 10 deletions doc/source/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,30 @@ See the :ref:`cookbook<cookbook.grouping>` for some advanced strategies.
Splitting an object into groups
-------------------------------

pandas objects can be split on any of their axes. The abstract definition of
Pandas objects can be split on any of their axes. The abstract definition of
grouping is to provide a mapping of labels to group names. To create a GroupBy
object (more on what the GroupBy object is later), you may do the following:
object, see below (more on what the GroupBy object is later). A
groupby can be applied in the following ways to a pandas object:

* grouped = obj.groupby(key)
* grouped = obj.groupby(key, axis='columns')
* grouped = obj.groupby([key1, key2])

.. code-block:: python

# default is axis=0
>>> grouped = obj.groupby(key)
>>> grouped = obj.groupby(key, axis=1)
>>> grouped = obj.groupby([key1, key2])
df = pd.DataFrame(
[('bird', 'Falconiformes', 389.0),
('bird', 'Psittaciformes', 24.0),
('mammal', 'Carnivora', 80.2),
('mammal', 'Primates', np.nan),
('mammal', 'Carnivora', 58)],
index=['falcon', 'parrot', 'lion', 'monkey', 'leopard'],
columns=('class', 'order', 'max_speed')
)

grouped = df.groupby('class')
grouped = df.groupby('order', axis='columns')
grouped = df.groupby(['class', 'order'])

The mapping can be specified many different ways:

Expand Down Expand Up @@ -239,7 +253,7 @@ the length of the ``groups`` dict, so it is largely just a convenience:
.. ipython::

@verbatim
In [1]: gb.<TAB>
In [1]: gb.<TAB> # noqa: E225, E999
gb.agg gb.boxplot gb.cummin gb.describe gb.filter gb.get_group gb.height gb.last gb.median gb.ngroups gb.plot gb.rank gb.std gb.transform
gb.aggregate gb.count gb.cumprod gb.dtype gb.first gb.groups gb.hist gb.max gb.min gb.nth gb.prod gb.resample gb.sum gb.var
gb.apply gb.cummax gb.cumsum gb.fillna gb.gender gb.head gb.indices gb.mean gb.name gb.ohlc gb.quantile gb.size gb.tail gb.weight
Expand Down Expand Up @@ -1301,11 +1315,15 @@ Piping can also be expressive when you want to deliver a grouped object to some
arbitrary function, for example:

.. code-block:: python
def mean(groupby):
return(groupby.mean())

df.groupby(['Store', 'Product']).pipe(report_func)
df.groupby(['Store', 'Product']).pipe(mean)

where ``report_func`` takes a GroupBy object and creates a report
from that.
where ``mean`` takes a GroupBy object and finds the mean of the Revenue and Quantity
columns repectively for each Store-Product combination. The ``mean`` function can
be any function that takes in a GroupBy object; the ``.pipe`` will pass the GroupBy
object as a parameter into the function you specify.

Examples
--------
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ exclude =
doc/source/basics.rst
doc/source/contributing_docstring.rst
doc/source/enhancingperf.rst
doc/source/groupby.rst


[yapf]
Expand Down