0

I want to set two columns with their index in a single index. But i can not merge table index. How could i merge table index using pandas or row python code?

I tried and get this https://ibb.co/7nZyxCM

Here is the sample code using PrettyTable https://ibb.co/Hh80LBJ

What i want to get : https://ibb.co/cQWf2Rz

Royel
  • 11
  • 4

1 Answers1

1

You can create the new MultiIndex (to be used for columns) e.g. from tuples:

cols = pd.MultiIndex.from_tuples([
    ('August', 'Invoice'), ('August', 'Sells'),
    ('September', 'Invoice'), ('September', 'Sells'),
    ('Growth', '1'),  ('Growth', '2') ])

Then just set it as columns in your df:

df.columns = cols
Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41