How can I convert a MultiIndex to a "regular" data frame?
Let's say I have this one:
columns = pd.MultiIndex.from_product([['C1', 'C2'], ['CA', 'CO', 'MI']],
names=['subject', 'type'])
data=np.array(list(string.ascii_lowercase))[:24].reshape((4, 6))
df = pd.DataFrame(
columns=columns,
data=data
)
And I want to convert to something like this (or anything with a similar idea):
columns = ['name', 'subject', 'type']
agents_data = [
(0, 'C1', 'CA', 'a'),
(0, 'C1', 'CO', 'b'),
...
(2, 'C2', 'CA', 'p'),
]
return pd.DataFrame.from_records(agents_data, columns=columns)
Is there any way to do this? (or something similar)
Something like this:
Into this:
Thank you!

