I have this data:
Date Month ProductCategory Sales
1/1/2009 2009-Jan Clothing 1755
1/1/2009 2009-Jan Grossery 524
1/1/2009 2009-Jan Toys 936
2/1/2009 2009-Feb Clothing 1729
2/1/2009 2009-Feb Grossery 496
2/1/2009 2009-Feb Toys
I want it as this table:
Date Month Clothing Sales Grossery Sales Toys Sales Total Sales
1/1/2009 2009-Jan 1755 524 936 3215
2/1/2009 2009-Feb 1729 496 2225
I tried this code:
train_cross =pd.crosstab([df_train.Date,df_train.Sales],
df_train.ProductCategory, margins=True)
.rename_axis(None,1)
.reset_index()train_cross
.head()
I got these results:
Date Sales Grossery Toys Clothing All
1/1/2009 524 1 0 0 1
1/1/2009 936 0 1 0 1
1/1/2009 1755 0 0 1 1
2/1/2009 496 1 0 0 1
2/1/2009 1729 0 0 1 1
Where I am wrong?