-1

How it would be possible in the easiest way to reshape this data ? I succeded coding a really long fonction but I was wondering wheather there's an easier way or not.

Here there is the image of the dataframe sample I would like to reshape

And here is the dataframe sample:

L = range(0,12)
df = pd.DataFrame({'Col_1': ['a', 'b', 'c','a', 'b', 'c','a', 'b', 'c','a', 'b', 'c'], 'Col_2': ['', '', '','', '', '','', '', '','', '', ''], 'Col_3': ['x', 'y', 'z','xx', 'yy', 'zz','xxx', 'yyy', 'zzz','x1', 'y2', 'z3']},index = L)

1 Answers1

0

I think this might work :

df.set_index(["Col_1",df.groupby("Col_1").cumcount()]).unstack().T.droplevel(1)

next time pls offer a minimal reproducible example for the community to help you out ^^

grymlin
  • 492
  • 1
  • 9