Skip to content

Pass a string to xarray.Dataset.reduce #7537

Answered by keewis
tqa236 asked this question in Q&A
Discussion options

You must be logged in to vote

additional keyword-arguments are passed through (this is what **kwargs in the docstring is referring to):

ds.reduce(aggregate, aggregation_method="mean")

you could also use functools.partial or a lambda to create a function that has that parameter pre-set:

ds.reduce(functools.partial(aggregate, aggregation_method="mean"))
ds.reduce(lambda ds_: aggregate(ds_, "mean"))

Edit: if aggregation_method is the name of a method on the dataset, we can also do:

getattr(ds, aggregation_method)()

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tqa236
Comment options

@keewis
Comment options

@tqa236
Comment options

Answer selected by tqa236
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants