Skip to content

Commit c30f456

Browse files
committed
DOC: Reapply code example fix from 41a2e47
1 parent 00b03f0 commit c30f456

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

doc/source/groupby.rst

+17-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,24 @@ 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(
72+
[('bird', 'Falconiformes', 389.0),
73+
('bird', 'Psittaciformes', 24.0),
74+
('mammal', 'Carnivora', 80.2),
75+
('mammal', 'Primates', np.nan),
76+
('mammal', 'Carnivora', 58)],
77+
index=['falcon', 'parrot', 'lion', 'monkey', 'leopard'],
78+
columns=('class', 'order', 'max_speed')
79+
)
80+
81+
df
7082
71-
# default is axis=0
72-
>>> grouped = obj.groupby(key)
73-
>>> grouped = obj.groupby(key, axis=1)
74-
>>> grouped = obj.groupby([key1, key2])
83+
# default is axis=0
84+
grouped = df.groupby('class')
85+
grouped = df.groupby('order', axis='columns')
86+
grouped = df.groupby(['class', 'order'])
7587
7688
The mapping can be specified many different ways:
7789

0 commit comments

Comments
 (0)