I have this dataframe:
no id type xa xa 01 02
1 bar any 2 3 1 3
2 foo all 3 4 0 1
the columns I need to transform is coming after the type
column, and I actually have plenty of them coming after the type
column and the column type is in the form of string and also integer.
so I need to transform any column coming after type
to be in dedicated columns which are category
and values
, and the expected result will be as follow:
no id type category values
1 bar any xa 2
1 bar any xa 3
1 bar any xa 1
1 bar any xa 3
2 foo all 01 3
2 foo all 01 4
2 foo all 01 0
2 foo all 01 1
I probably can use df.melt, but I am still not sure on how to use it in my case.
How do I suppose to write my script so that I can get my desired dataframe?
Thanks in advance.