Pandas DataFrame.reset_index for columns [duplicate]

Answer to the second question:

df.columns = df.columns.droplevel(level)

First question is as @AndyHayden points out not that straight forward. It only would make sense if your columns names are of the same type as your column values.


Here's a really dumb way to turn your columns into tuples instead:

df.columns = list(df.columns)

You can build on that to get whatever you want, for example if you had a 2 level MultiIndex, to remove the outermost level, you could just do:

df.columns = [col[1] for col in df.columns]

You can't do fancy indexing over the iteration because it's generating tuples, but you can do things like:

df.columns = MultiIndex.from_tuples([col[1:] for col in df.columns])

So you have some options there.