I have a dataframe like as shown below
df = pd.DataFrame({
'subject_ID':[1,2,3,4,5,6,7,8],
'1st_date':['1/1/2020','3/3/2000','13/11/2020','24/05/1998','30/03/1971','30/03/1971','30/03/1971','30/03/1971'],
'1st_marks':[31,32,34,45,56,78,74,32],
'1st_1st_retest_marks':[31,32,34,45,56,78,74,32],
'1st_2nd_retest_marks':[31,32,34,45,56,78,74,32],
'2nd_date':['1/2/2020','3/4/2000','13/12/2020','24/06/1998','30/04/1971','21/04/1971','10/04/1971','20/04/1971'],
'2nd_marks':[31,32,34,45,56,78,74,32],
'3rd_date':['1/1/2010','3/3/2005','13/11/2021','24/05/1898','30/03/1981','30/03/1991','30/03/1901','30/03/1871'],
'3rd_marks':[31,32,34,45,56,78,74,32]})
I tried the below
df = pd.melt(df, id_vars =['subject_ID']) # incorrect output
df = pd.melt(df,id_vars = ['subject_ID','1st_date'] #incorrect output
In my real data, I have more than 100 date columns and corresponding mark values for every subject.
How can I pass all 100 dates as input to melt
function
I expect my output to be like as shown below (sample for subject_id = 1)
Please don;t use any pattern from column names as in real data, the column names doesn;t have any pattern like 1st, 2nd, 3rd etc