I want to transpose below data using python pandas. But I am not getting a proper solution as i want transpose specific columns.
CodePudding user response:
Try using melt
df = pd.DataFrame({"ID":["a","a","a","a"],
"Date":["date1","date2","date3","date4"],
"H1":[1,1,1,1],
"H2":[2,2,2,2],
"H3":[3,3,3,3],
"H4":[4,4,4,4]})
df1 = pd.melt(df,id_vars =['ID','Date'], value_vars =['H1','H2','H3','H4'])
Output of df;
Output of df1;