Hi I have a DataFrame/Series with 2-level multi-index and one column. I would like to take the second-level index and use it as a column. For example (code taken from multi-index docs):
import pandas as pd
import numpy as np
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'])
s = pd.DataFrame(np.random.randn(8), index=index, columns=["col"])
Which looks like:
first second
bar one -0.982656
two -0.078237
baz one -0.345640
two -0.160661
foo one -0.605568
two -0.140384
qux one 1.434702
two -1.065408
dtype: float64
What I would like is to have a DataFrame with index [bar, baz, foo, qux] and columns [one, two].