0

I am trying to combine multilevel column names for a data frame into a single level. I don't want to drop any level just combine them. Getting them into a tuple format can also work (a,1) (a,2) and so on.

For example:

I have a data frame:

enter image description here

I want the output in following format:

enter image description here

Rupal
  • 51
  • 3
  • `df.columns = [f'{f}_{s}' for f, s in df.columns]` like [this answer](/a/51735628) or `df.columns = ['_'.join(tuple(map(str, t))) for t in df.columns]` like [this answer](/a/45214611) but there are lots of options in the linked thread. – Henry Ecker Feb 15 '22 at 03:19
  • f.columns = f.columns.map('_'.join).str.strip() This works, thank you! – Rupal Feb 15 '22 at 03:26

0 Answers0