Closed
Description
labels = list("zyx")
data = [14, 15, 12, 13, 10, 11]
ordered = False
cidx = pd.CategoricalIndex(labels, categories=sorted(labels), ordered=ordered)
cidx2 = pd.CategoricalIndex(["u", "v"], ordered=ordered)
midx = MultiIndex.from_product([cidx, cidx2])
df = DataFrame([sorted(data)], columns=midx)
print(df)
# z y x
# u v u v u v
# 0 10 11 12 13 14 15
print(df.stack([0, 1]))
# 0 x u 14
# v 15
# y u 12
# v 13
# z u 10
# v 11
# dtype: int64
The stacked result should maintain the order z y x
.