My Dataframe looks similar to this
Date Key Value1 Value2
D1 1A 2
D1 2A 1 2
D2 3B 1 3
D2 1A 3
D3 2A 5
As you can see, the Key
itself ain't primary, However if we consider Date
and Key
together, each observation finds it as a primary key.
Now I wish to achieve that for every observation where Value1
and Value2
both are present, duplicate the row and break them into two rows. Something like this:
Date Key Value1 Value2 Value
D1 1A 2 2
D1 2A 1 2 1
D1 2A 1 2 2
D2 3B 1 3 1
D2 3B 1 3 3
D3 2A 5 5
Is there anyway I can achieve this? Thanks in advance.