0

I have two different dataframes.

One looks like:

     Date          StoreID     MerchandiseType     Count
     04/01/2020    1           Hat                 2
     04/01/2020    1           Shirt               4

The other looks like:

     Date        StoreID     Hat    Shirt
     04/01/2020  1           2      4

I would like to transform dataframe 2, so that it is structured like dataframe 1 and then union. Any suggestions?

dcrowley01
  • 141
  • 2
  • 12

1 Answers1

0

Do:

df2 = df2.melt(id_vars=['Date', 'StoreID'], value_vars=['Hat', 'Shirt'])

This will give you the right format and then you can merge.

Output: enter image description here

whege
  • 1,391
  • 1
  • 5
  • 13