0

I have this dataframe:

id1 id2 code
1234 qw123 4h2
5678 de121 23f
9012 - 64r

The desired output is:

id1 code
1234 4h2
qw123 4h2
5678 23f
de121 23f
9012 64r

I'm trying to kind of melt/concat the id2 column to id1 and keep its value from id correspondingly, so at the end I can have one column with ids and one column with codes. Also is it possible to make the code generic, in order to not hard code the names of the id columns, because there could be a possibility that the id columns could be 2 or 3?

I'd appreciate any kind of help! Thanks

Y.C.T
  • 113
  • 10
  • Why my question is being closed? The linked question is different case, I dont have a column that I can use in `melt` as `id_vars`. I want to combine the two id columns and then kind of melt the values in `code` – Y.C.T Jun 14 '21 at 10:03

0 Answers0