Skip to content

Struggling to go from single indexing to multi-indexing #9829

Closed Answered by dcherian
Ashwolaa asked this question in Q&A
Discussion options

You must be logged in to vote

It is not easy to figure this out sadly.

from xarray.indexes import PandasMultiIndex

coord_names = ["isOn", "delay2", "delay1"]

(
    ds
    # drop the existing index variable (required for set_xindex)
    .drop_vars("index")
    # set the desired new dimensions as coordinate variables
    .set_coords(coord_names)
    # Assign a PandasMultiIndex
    .set_xindex(coord_names, PandasMultiIndex)
    # "unstack" to a nD array
    .unstack("index")
)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Ashwolaa
Comment options

You must be logged in to vote
0 replies
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