Skip to content Skip to sidebar Skip to footer

Transform Pandas Dataframe

I have DataFrame that looks like this exec ms tp lu ru 0 exec1 16.0 240.87 2.30 0.85 1 exec1 16.0 243.72 2.35 0.84 2 exec1 16.0

Solution 1:

May need groupby +cumcount create a additional key , then do pivot transform , here I am using unstack , if you need check pivot , personally think this explain better than the official document

df.assign(key=df.groupby(['exec','ms']).cumcount()).set_index(['exec','ms','key']).unstack([1])

Post a Comment for "Transform Pandas Dataframe"