-
- Notifications
You must be signed in to change notification settings - Fork 19.2k
Closed
Labels
BugMultiIndexReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode
Milestone
Description
starting PR is here: #6647
By reading the docs on Dataframe.reindex(), I would have guessed (not sure what "broadcast" is...) that this works:
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'], ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']] tuples = zip(*arrays) index = MultiIndex.from_tuples(tuples, names=['first', 'second']) df = DataFrame({"a":list("abcdefgh"), "b":list("abcdefgh")}, index=index) order = ["baz", "bar", "foo", "qux"] df.reindex(order, level=0) # still returns the same orderingIt works that way on a normal index (without the level argument):
df2 = DataFrame({"a":list("ABCD")}, index=['bar', 'baz', 'foo', 'qux']) df2.reindex(order) # new orderingIt also works when I pass a list of tuples:
_new_index = [] for _a in order: for _b in df.index.levels[1]: _new_index.append((_a, _b)) df.reindex(_new_index) # new orderingMetadata
Metadata
Assignees
Labels
BugMultiIndexReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode