python xarray - groupby.apply method taking more than one arguments -
in xarray
document, groupby.apply
method can apply function different groups. in documentation,
in [11]: def standardize(x): ....: return (x - x.mean()) / x.std() ....: in [12]: arr.groupby('letters').apply(standardize)
however, how can put argument standardize function? i.e.
def standardize(x, y): ....: return (x - x.mean()) / x.std() + y.sum() arr.groupby('letters').apply(standardize(x, y))??
it obvious not right. now, there no way call apply method.
to apply operation on multiple variables @ once, put multiple dataarray
objects single xarray.dataset
, e.g.,
# foo , bar xarray.dataarray objects ds = xarray.dataset({'x': foo, 'y': bar}) def standardize(ds): return (ds.x - ds.x.mean()) / ds.x.std() + ds.y.sum() ds.groupby('letters').apply(standardize)
Comments
Post a Comment