Here is a dataframe data_1.
data_1=pd.DataFrame({'id':['1','1','1','1','1','2','2','2','2','2'],
'date':['20220325','20220325','20220325','20220327','20220327','20220705','20220705','20220706','20220706','20220706'],
'base':["wt","bmi","p","wt","wt","bmi","bmi","wt","p","bmi"],
'value':['75','21','25','76','77','19','18','85','23','19']},
)
data_1['id'] = pd.to_numeric(data_1['id'], errors='coerce')
data_1['date'] = pd.to_numeric(data_1['date'], errors='coerce')
data_1['value'] = pd.to_numeric(data_1['value'], errors='coerce')
I want to make this data_1 as follows:
data_1=pd.DataFrame({'id':[1,1,1,2,2,2],
'date':[20220325,20220327,20220327,20220705,20220705,20220706],
'wt':[75,76,77,"","",85],
'bmi':[21,"","",19,18,19],
'p':[25,"","","","",23]})
I tried pivot_table ,but the output is not the same as I expected.
Moreover, I need to save the data_1 as csv file, but the there are no columns id and date in the csv file that I made.
Is there any method to change the data_1 as my expected output?