Skip to content

Commit 003609a

Browse files
LJArendsejreback
authored andcommitted
DOC: fix flake8 issue in groupby.rst (#24363)
1 parent 08c920e commit 003609a

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Diff for: doc/source/groupby.rst

+24-10
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,21 @@ pandas objects can be split on any of their axes. The abstract definition of
6666
grouping is to provide a mapping of labels to group names. To create a GroupBy
6767
object (more on what the GroupBy object is later), you may do the following:
6868

69-
.. code-block:: python
69+
.. ipython:: python
70+
71+
df = pd.DataFrame([('bird', 'Falconiformes', 389.0),
72+
('bird', 'Psittaciformes', 24.0),
73+
('mammal', 'Carnivora', 80.2),
74+
('mammal', 'Primates', np.nan),
75+
('mammal', 'Carnivora', 58)],
76+
index=['falcon', 'parrot', 'lion', 'monkey', 'leopard'],
77+
columns=('class', 'order', 'max_speed'))
78+
df
7079
71-
# default is axis=0
72-
>>> grouped = obj.groupby(key)
73-
>>> grouped = obj.groupby(key, axis=1)
74-
>>> grouped = obj.groupby([key1, key2])
80+
# default is axis=0
81+
grouped = df.groupby('class')
82+
grouped = df.groupby('order', axis='columns')
83+
grouped = df.groupby(['class', 'order'])
7584
7685
The mapping can be specified many different ways:
7786

@@ -239,7 +248,7 @@ the length of the ``groups`` dict, so it is largely just a convenience:
239248
.. ipython::
240249

241250
@verbatim
242-
In [1]: gb.<TAB>
251+
In [1]: gb.<TAB> # noqa: E225, E999
243252
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
244253
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
245254
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
@@ -1300,12 +1309,17 @@ Now, to find prices per store/product, we can simply do:
13001309
Piping can also be expressive when you want to deliver a grouped object to some
13011310
arbitrary function, for example:
13021311

1303-
.. code-block:: python
1312+
.. ipython:: python
1313+
1314+
def mean(groupby):
1315+
return groupby.mean()
13041316
1305-
df.groupby(['Store', 'Product']).pipe(report_func)
1317+
df.groupby(['Store', 'Product']).pipe(mean)
13061318
1307-
where ``report_func`` takes a GroupBy object and creates a report
1308-
from that.
1319+
where ``mean`` takes a GroupBy object and finds the mean of the Revenue and Quantity
1320+
columns repectively for each Store-Product combination. The ``mean`` function can
1321+
be any function that takes in a GroupBy object; the ``.pipe`` will pass the GroupBy
1322+
object as a parameter into the function you specify.
13091323

13101324
Examples
13111325
--------

Diff for: setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ exclude =
5353
doc/source/basics.rst
5454
doc/source/contributing_docstring.rst
5555
doc/source/enhancingperf.rst
56-
doc/source/groupby.rst
5756

5857

5958
[yapf]

0 commit comments

Comments
 (0)