Closed
Description
I often work with datasets that consist out of a lot of data_variables and coordinates.
Often I am only concerned about a subset of variables, and for convenience drop all but a selected list of variables with a little snippet like this:
Code Sample, a copy-pastable example if possible
def xr_keep(obj, varlist):
"""drop all data_vars exept the ones provided in `varlist` """
obj = obj.copy()
drop_vars = [a for a in obj.data_vars if a not in varlist]
return obj.drop(drop_vars)
I would love to have this functionality available as a DataArray/Dataset function. It could look something like da_slim = da.drop_all_but(['var1, 'var3'])
. Would this be of interest to people here? Then I could try to put in a PR.