pandas MultiIndex How to change MultiIndex columns to standard columns


Example

Given a DataFrame with MultiIndex columns

# build an example DataFrame
midx = pd.MultiIndex(levels=[['zero', 'one'], ['x','y']], labels=[[1,1,0,],[1,0,1,]])
df = pd.DataFrame(np.random.randn(2,3), columns=midx)

In [2]: df
Out[2]: 
        one                zero
          y         x         y
0  0.785806 -0.679039  0.513451
1 -0.337862 -0.350690 -1.423253

If you want to change the columns to standard columns (not MultiIndex), just rename the columns.

df.columns = ['A','B','C']
In [3]: df
Out[3]: 
          A         B         C
0  0.785806 -0.679039  0.513451
1 -0.337862 -0.350690 -1.423253