0

I want to set all column names at one line. How should I do it? I tried many things but couldn't do it, including renaming columns.

image

Esther
  • 356
  • 8

1 Answers1

0

You need to flatten your multiindex column header.

df.columns = df.columns.map('_'.join)

Or using f-string with list comprehension:

df.columns = [f'{i}_{j}' if j else f'{i}' for i, j in df.columns]
Scott Boston
  • 147,308
  • 15
  • 139
  • 187