Pandas: getting rid of the multiindex

Viewed 30468

After grouping and counting a dataframe I'm trying to remove the multiindex like this:

df = df[['CID','FE', 'FID']].groupby(by=['CID','FE']).count()
              .unstack().reset_index()

Printing the columns (df.colums) shows that it is still a MultiIndex.

MultiIndex(levels=[['FID', 'CID'], [...]]

I can't access the column CID via df['CID'].

2 Answers
Related