Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas DataFrame.reset_index for columns

Tags:

python

pandas

Is there a reset_index equivalent for the column headings? In other words, if the column names are an MultiIndex, how would I drop one of the levels?

like image 299
Alex Rothberg Avatar asked Oct 20 '13 06:10

Alex Rothberg


1 Answers

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.

like image 163
joris Avatar answered Oct 12 '22 23:10

joris