0

i am looking for some help on how to format a pandas dataframe

input

date         A     B
8/1/2022   $100  $50

desired output

date        type   amount
8/1/2022     $A     $100
8/1/2022     $B      $50
Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

0

You can use pandas.melt. Your identifier column is date.

try:

df = df.melt(id_vars=["date"], 
        var_name="type", 
        value_name="amount")
mmustafaicer
  • 434
  • 6
  • 15