How to convert the multi index series into a Data frame in python?

ipython

#1

I have created a series in ipython notebook in which there are two levels(multi index series) .I want to know how to convert the multi index series to a Data frame in python.
data = Series(np.random.randn(10),
…: index=[[‘a’, ‘a’, ‘a’, ‘b’, ‘b’, ‘b’, ‘c’, ‘c’, ‘d’, ‘d’],
…: [1, 2, 3, 1, 2, 3, 1, 2, 2, 3]])

data
a 1 0.670216
2 0.852965
3 -0.955869
b 1 -0.023493
2 -2.304234
3 -0.652469
c 1 -1.218302
2 -1.332610
d 2 1.074623
3 0.723642

#2

@sid100158,

You can use reset_index() command to transfer index values into the DataFrame as columns. First we convert the series to Data Frame and after that we will apply reset_index() command to convert indexes into columns.

import numpy as np
import pandas as pd
data = pd.Series(np.random.randn(10),index=[['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd', 'd'],[1, 2, 3, 1, 2, 3, 1, 2, 2, 3]]) 
data

test=pd.DataFrame(data)
check=test.reset_index(inplace=True)
check

Regards,
Mark