Add groupby and groupby_apply functionality to metadata #383
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR brings grouping functionality to metadata, inspired by pandas implementation
Two new class methods are added for objects with metadata:
obj.groupby(by, get_group=None)
by
(required) is a string or list of strings corresponding to the metadata columns by which to groupget_group
(optional) can be specified to return a new, reduced object filtered to the groupget_group
get_group
is not suppliedget_group
if it is suppliedobj.groupby_apply(by, func, grouped_arg=None, **func_kwargs)
by
(required) same as abovefunc
(required) function to apply to each group of the objectgrouped_arg
(optional) string corresponding to the function argument that the grouped object is passed as. ifNone
, the grouped object is sent at the first positional argument.func_kwargs
(optional) dictionary of other required or optional keyword arguments that are passed tofunc
.