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
Post a Comment