arrays = [
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
["one", "two", "one", "two", "one", "two", "one", "two"],
]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=["first", "second"])
以下で、最初の①と同じような結果が得られる
iterables = [["bar", "baz", "foo", "qux"], ["one", "two"]]
pd.MultiIndex.from_product(iterables, names=["first", "second"])
df = pd.DataFrame([[“bar”, “one”], [“bar”, “two”], [“foo”, “one”], [“foo”, “two”]],columns=[“first”, “second”],)pd.MultiIndex.from_frame(df)
arrays = [[“bar”, “bar”, “baz”, “baz”, “foo”, “foo”, “qux”, “qux”],[“one”, “two”, “one”, “two”, “one”, “two”, “one”, “two”],]s = pd.Series(np.random.randn(8), index=arrays)