Best Way To Pivot/rotate Data Set
I've got the following data frame df = pd.DataFrame({ '1': ['Mon (07/08)','Sales', '2'], '2': ['Mon (07/08)','Stock','3'], '3': ['Mon (07/0
Solution 1:
Take the transpose, then use pivot
to reshape. After that, it's just a matter of formatting the axes with rename_axis
.
# reshapedf = df.T.pivot(index=0, columns=1, values=2)
# format axesdf = df.rename_axis(None).rename_axis(None, 1)
The resulting output:
Qty Sales Stock
Mon (07/08) 423
Tue (08/08) 645
Post a Comment for "Best Way To Pivot/rotate Data Set"