0

I have the following dataframe:

Material End Date Start Date Qty
A 10-Dec 10-Dec 4
B 13-Dec 14-Dec 2
C 14-Dec 16-Dec 3
D 15-Dec 15-Dec 0
E 16-Dec 17-Dec 1

I want to unpivot this dataframe in a way that gives me the output: Here where the end date and start date is same, should not be printed twice.

Material Date Qty
A 10-Dec 4
B 13-Dec 2
B 14-Dec 2
C 14-Dec 3
C 15-Dec 3
C 16-Dec 3
D 15-Dec 0
E 16-Dec 1
E 17-Dec 1

Can I get the code for this ?

kanika
  • 37
  • 4
  • 1
    `df.melt(id_vars=["Material", "Qty"], value_vars=["End Date", "Start Date"], value_name="Date").drop("variable", axis=1)` ? – Timeless Jan 25 '23 at 05:48
  • `df.melt(id_vars=["Material", "Qty"], value_vars=["End Date", "Start Date"], value_name="Date").drop("variable", axis=1).drop_duplicates()` ? – jezrael Jan 25 '23 at 06:53

0 Answers0