pandas.Grouper¶
- class pandas.Grouper(key=None, level=None, freq=None, axis=None, sort=False)¶
A Grouper allows the user to specify a groupby instruction for a target object
This specification will select a column via the key parameter, or if the level and/or axis parameters are given, a level of the index of the target object.
These are local specifications and will override ‘global’ settings, that is the parameters axis and level which are passed to the groupby itself.
Parameters : key : string, defaults to None
groupby key, which selects the grouping column of the target
level : name/number, defaults to None
the level for the target index
freq : string / freqency object, defaults to None
This will groupby the specified frequency if the target selection (via key or level) is a datetime-like object
axis : number/name of the axis, defaults to None
sort : boolean, default to False
whether to sort the resulting labels
additional kwargs to control time-like groupers (when freq is passed)
closed : closed end of interval; left or right
label : interval boundary to use for labeling; left or right
convention : {‘start’, ‘end’, ‘e’, ‘s’}
If grouper is PeriodIndex
Returns : A specification for a groupby instruction
Examples
>>> df.groupby(Grouper(key='A')) : syntatic sugar for df.groupby('A') >>> df.groupby(Grouper(key='date',freq='60s')) : specify a resample on the column 'date' >>> df.groupby(Grouper(level='date',freq='60s',axis=1)) : specify a resample on the level 'date' on the columns axis with a frequency of 60s
Attributes
ax groups