0

I have a dataframe df1 where

ID    Name     Fee1  Amount1  Fee2  Amount2  Fee3   Amount3
1     Abc       05     100     06     115     15      50
2     Def       12     215     07     215     08      60
3     Ghi       17     120     05     60      06      80
4     Jkl       03     310     06     150     15      55

I would like to transpose Fees and Amounts in multiple rows like below:

ID    Name     Fee  Amount
1     Abc       05     100
1     Abc       06     115
1     Abc       15      50
2     Def       12     215
2     Def       07     215
2     Def       08      60
3     Ghi       17     120
3     Ghi       05      60
3     Ghi       06      80
4     Jkl       03     310
4     Jkl       06     150
4     Jkl       15      55

Thank you in advance.

mozway
  • 194,879
  • 13
  • 39
  • 75
S_Python
  • 13
  • 2
  • 1
    `pd.wide_to_long(df, stubnames=['Fee', 'Amount'], i=['ID', 'Name'], j='x').reset_index().drop(columns='x')` – mozway Mar 08 '23 at 15:10
  • `pd.wide_to_long(df, ['Fee', 'Amount'], i=['Name', 'ID'], j='').droplevel(-1).reset_index()` – SomeDude Mar 08 '23 at 15:18

0 Answers0