I am performing an image analysis, in which the output has the following format: format 1
in which "slice" refers to which sample corresponds
but I need it to be like this
where each row corresponds to a sample
I tried this code:
df['g'] = (df.groupby('Slice').cumcount() + 1).astype(str)
df1 = df.set_index(['Slice','g']).unstack()
df1.sort_index(axis=1,level=1, inplace=True)
df1.columns = [''.join(col) for col in df1.columns]
df1.reset_index(inplace=True)
df1 = df1.set_index("Slice")
but it groups the first value of each sample, which I don't need and i don't know how to fix it.