issue_comments: 1494033789
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/7239#issuecomment-1494033789 | https://api.github.com/repos/pydata/xarray/issues/7239 | 1494033789 | IC_kwDOAMm_X85ZDSV9 | 85181086 | 2023-04-03T10:01:52Z | 2023-04-03T10:01:52Z | NONE | a workaround for achieving this would be to use the apply method of xarray data structures along with the expand_dims method. Here's an example of how we can use it: ``` import xarray as xr dataset = xr.Dataset(data_vars={'foo': 1, 'bar': 2}) Define a function that expands the given variable along a new dimensiondef expand_variable(da): if da.name == 'foo': return da.expand_dims('zar') else: return da Use the apply method to apply the function to only the desired variablesexpanded_dataset = dataset.apply(expand_variable, keep_attrs=True) print(expanded_dataset) ``` Here, the expand_variable function is defined to only expand the variable with the name 'foo' along a new dimension. The apply method is used to apply this function to each data variable in the dataset, but only 'foo' is actually modified. |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
1429172192 |