I have something like this:
Values Time 22 0 45 1 65 2 78 0 12 1 45 2
and I want this
This is pivot creating the index with cumcount
pivot
cumcount
df['idx'] = 'Val' + (df.groupby('Time').cumcount()+1).astype(str) df.pivot(index='idx', columns='Time', values='Values').rename_axis(None)
Output:
Time 0 1 2 Val1 22 45 65 Val2 78 12 45