Created
February 19, 2015 23:15
-
-
Save shoyer/c16b1f9ec4f7c0de9e64 to your computer and use it in GitHub Desktop.
xray nd-groupby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def nd_groupby_apply(ds, dims, func): | |
if isinstance(dims, str): | |
dims = [dims] | |
if len(dims) > 1: | |
func = functools.partial(nd_groupby_apply, dims=dims[1:], func=func) | |
return ds.groupby(dims[0]).apply(func) | |
def nd_group_over_apply(ds, dims, func): | |
if isinstance(dims, str): | |
dims = [dims] | |
by_dims = [d for d in ds.dims if d not in dims] | |
return nd_groupby_apply(ds, by_dims, func) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment