I want to transpose below data using python pandas. But I am not getting a proper solution as i want transpose specific columns.
Input Data Format-
Output Data Format-
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.