home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 217347106

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
217347106 MDU6SXNzdWUyMTczNDcxMDY= 1331 Convert an existing xarray dimension into a MultiIndex 1217238 closed 0     3 2017-03-27T19:17:22Z 2017-03-28T18:11:02Z 2017-03-28T18:11:02Z MEMBER      

Suppose I have two xarray Datasets, each defined along the 'x' axis: python ds1 = xarray.Dataset({'foo': (('x',), [1, 2, 3])}, {'x': [1, 2, 3], 'y': 'a'}) ds2 = xarray.Dataset({'foo': (('x',), [4, 5, 6])}, {'x': [1, 2, 3], 'y': 'b'}) <xarray.Dataset> Dimensions: (x: 3) Coordinates: y |S1 'a' * x (x) int64 1 2 3 Data variables: foo (x) int64 1 2 3

Now I want to stack them along a new MultiIndex 'yx' that consists of y and x levels: python desired = xarray.Dataset({'foo': (('yx',), [1, 2, 3, 4, 5, 6])}, {'yx': pandas.MultiIndex.from_product([['a', 'b'], [1, 2, 3]], names=['y', 'x'])}) <xarray.Dataset> Dimensions: (yx: 6) Coordinates: * yx (yx) MultiIndex - y (yx) object 'a' 'a' 'a' 'b' 'b' 'b' - x (yx) int64 1 2 3 1 2 3 Data variables: foo (yx) int64 1 2 3 4 5 6

How can this be achieved with the minimum effort? What is the missing utility function that we need? I attempted to use set_index and swap_dims but so far have been unsuccessful.

@benbovy any ideas? I think something similar may have come up when we were discussing your set_index PR.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1331/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 0.575ms · About: xarray-datasette