df have
cola colb colc cold cole colf colg
1 x y 10 15 20 25
2 x y 11 16 27 28
3 x y 12 14 20 30
df want
cola colb colc colD colE
1 x y 10 20
1 x y 15 25
2 x y 11 27
2 x y 16 28
3 x y 12 20
3 x y 14 30
Looking to pivot df have (cold and cole become colD, colf and colg become colE). In reality I have many more columns than cola and colb (about 50 columns) that will NOT be pivoted, only the last 4 are pivoting into 2 columns.
Have tried: pd.melt(df_have, id_vars=['cola, colb'], var_name='colD')
But this requires me to add all 50 columns to id_vars and I can only do colD creation and colE creation in multiple steps- looking for a faster solution