pandas - Drop level from one specific column -


inspired pandas: drop level multi-level column index?

i have multilevel dataframe:

  | l |     |   +---+---+---+   |   | b | c | --+---+---+---+ 0 | ¦ 1 | 2 | 1 | b ¦ 3 | 4 | 

i need flatten column a @ level 0

so like:

  +---+---+---+   | l | b | c | --+---+---+---+ 0 | ¦ 1 | 2 | 1 | b ¦ 3 | 4 | 

df.columns = df.columns.droplevel() produces

  +---+---+---+   |   | b | c | --+---+---+---+ 0 | ¦ 1 | 2 | 1 | b ¦ 3 | 4 | 

i struggling produce toy example well

try this

df.columns = [c[-1] c in df.columns] 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -