@@ -62,30 +62,16 @@ See the :ref:`cookbook<cookbook.grouping>` for some advanced strategies.
62
62
Splitting an object into groups
63
63
-------------------------------
64
64
65
- Pandas objects can be split on any of their axes. The abstract definition of
65
+ pandas objects can be split on any of their axes. The abstract definition of
66
66
grouping is to provide a mapping of labels to group names. To create a GroupBy
67
- object, see below (more on what the GroupBy object is later). A
68
- groupby can be applied in the following ways to a pandas object:
69
-
70
- * grouped = obj.groupby(key)
71
- * grouped = obj.groupby(key, axis='columns')
72
- * grouped = obj.groupby([key1, key2])
67
+ object (more on what the GroupBy object is later), you may do the following:
73
68
74
69
.. code-block :: python
75
70
76
- df = pd.DataFrame(
77
- [(' bird' , ' Falconiformes' , 389.0 ),
78
- (' bird' , ' Psittaciformes' , 24.0 ),
79
- (' mammal' , ' Carnivora' , 80.2 ),
80
- (' mammal' , ' Primates' , np.nan),
81
- (' mammal' , ' Carnivora' , 58 )],
82
- index = [' falcon' , ' parrot' , ' lion' , ' monkey' , ' leopard' ],
83
- columns = (' class' , ' order' , ' max_speed' )
84
- )
85
-
86
- grouped = df.groupby(' class' )
87
- grouped = df.groupby(' order' , axis = ' columns' )
88
- grouped = df.groupby([' class' , ' order' ])
71
+ # default is axis=0
72
+ >> > grouped = obj.groupby(key)
73
+ >> > grouped = obj.groupby(key, axis = 1 )
74
+ >> > grouped = obj.groupby([key1, key2])
89
75
90
76
The mapping can be specified many different ways:
91
77
0 commit comments