I have the following data (df) :
I want to make a simple pivot (nested pivot like the following) where the labels are repeating like the yellow colored cells.
However, I am getting this
My code :
group_by = df.groupby(['meta_weight','meta_weight_type', 'weight_conversion'])['Sales_Unit'].sum()
print(group_by)
Please tell me how can I repeat the labels, as we do it in pivot table in excel. Thank you
CodePudding user response:
There is problem values are by default only not shown, so possible solution is turn off display this way:
with pd.option_context('display.multi_sparse', False):
print(df)
CodePudding user response:
It got solved by resetting index values
group_by_meta = df.groupby(['meta_weight','meta_weight_type', 'weight_conversion'])['Sales_Unit'].sum()
print(group_by_meta)
group_by_meta = group_by_meta.reset_index()