@@ -141,25 +141,37 @@ def _last(x):
141
141
142
142
class Grouper (object ):
143
143
"""
144
- A Grouper allows the user to specify a groupby instruction
144
+ A Grouper allows the user to specify a groupby instruction for a target object
145
+
146
+ This specification will select a column via the key parameter, or if the level and/or
147
+ axis parameters are given, a level of the index of the target object.
148
+
149
+ These are local specifications and will override 'global' settings, that is the parameters
150
+ axis and level which are passed to the groupby itself.
145
151
146
152
Parameters
147
153
----------
148
- key : groupby key, default None
149
- level : name, int level number, default None
150
- freq : string / freqency object, default None
151
- sort : boolean, whether to sort the resulting labels, default True
154
+ key : string, defaults to None
155
+ groupby key, which selects the grouping column of the target
156
+ level : name/number, defaults to None
157
+ the level for the target index
158
+ freq : string / freqency object, defaults to None
159
+ This will groupby the specified frequency if the target selection (via key or level) is
160
+ a datetime-like object
161
+ axis : number/name of the axis, defaults to None
162
+ sort : boolean, default to False
163
+ whether to sort the resulting labels
152
164
153
165
Returns
154
166
-------
155
167
A specification for a groupby instruction
156
168
157
169
Examples
158
170
--------
159
- df.groupby(Group (key='A')) : syntatic sugar for df.groupby('A')
160
- df.groupby(Group (key='date',freq='60s')) : specify a resample on the column 'date'
161
- df.groupby(Group (level='date',freq='60s',axis=1)) :
162
- specify a resample on the level 'date' on the columns axis with a frequency of 60s
171
+ >>> df.groupby(Grouper (key='A')) : syntatic sugar for df.groupby('A')
172
+ >>> df.groupby(Grouper (key='date',freq='60s')) : specify a resample on the column 'date'
173
+ >>> df.groupby(Grouper (level='date',freq='60s',axis=1)) :
174
+ specify a resample on the level 'date' on the columns axis with a frequency of 60s
163
175
164
176
"""
165
177
@@ -186,7 +198,7 @@ def __init__(self, key=None, level=None, freq=None, axis=None, sort=False):
186
198
def ax (self ):
187
199
return self .grouper
188
200
189
- def get_grouper (self , obj ):
201
+ def _get_grouper (self , obj ):
190
202
191
203
"""
192
204
Parameters
@@ -198,10 +210,10 @@ def get_grouper(self, obj):
198
210
a tuple of binner, grouper, obj (possibly sorted)
199
211
"""
200
212
201
- self .set_grouper (obj )
213
+ self ._set_grouper (obj )
202
214
return self .binner , self .grouper , self .obj
203
215
204
- def set_grouper (self , obj , sort = False ):
216
+ def _set_grouper (self , obj , sort = False ):
205
217
"""
206
218
given an object and the specifcations, setup the internal grouper for this particular specification
207
219
@@ -252,7 +264,7 @@ def set_grouper(self, obj, sort=False):
252
264
self .grouper = ax
253
265
return self .grouper
254
266
255
- def get_binner_for_grouping (self , obj ):
267
+ def _get_binner_for_grouping (self , obj ):
256
268
raise NotImplementedError
257
269
258
270
@property
@@ -1685,7 +1697,7 @@ def __init__(self, index, grouper=None, obj=None, name=None, level=None,
1685
1697
elif isinstance (self .grouper , Grouper ):
1686
1698
1687
1699
# get the new grouper
1688
- grouper = self .grouper .get_binner_for_grouping (self .obj )
1700
+ grouper = self .grouper ._get_binner_for_grouping (self .obj )
1689
1701
self .obj = self .grouper .obj
1690
1702
self .grouper = grouper
1691
1703
if self .name is None :
@@ -1795,7 +1807,7 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True):
1795
1807
1796
1808
# a passed in Grouper, directly convert
1797
1809
if isinstance (key , Grouper ):
1798
- binner , grouper , obj = key .get_grouper (obj )
1810
+ binner , grouper , obj = key ._get_grouper (obj )
1799
1811
return grouper , [], obj
1800
1812
1801
1813
# already have a BaseGrouper, just return it
0 commit comments