pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.61k stars 1.08k forks source link

Feature: Aggregate using one or more operations over the specified axis. #9479

Open kobebryant432 opened 1 month ago

kobebryant432 commented 1 month ago

Is your feature request related to a problem?

I'm always frustrated when I need to resample a ds and the resampling method is different for the variables present, i.e. for one variable I want the sum and for the other the mean.

Describe the solution you'd like

Ideally there would be some functionality similar to pandas .agg functionality. Not sure if this is feasible.

ds = ds.resample(time="D").agg({"pr":"sum","tas":np.mean})

Describe alternatives you've considered

Current workaround which gets unwieldy for multiple variables.

ds_pr = ds.pr.resample(time="D").sum()
ds_tas = ds.tas.resample(time="D").mean()

ds = xr.merge([ds_pr, ds_tas])

Additional context

No response

welcome[bot] commented 1 month ago

Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!