How to access output of groupby as a dataframe in python?

python

#1

Hi,

Recently I have started learning Python and have some doubts with dataframe.groupby output. It is regarding the output of dataframe.groupby. Here, I am not able to access each key value as dataframe column.

Below I have used groupby statement to populate Region and Zone wise sum of Sales but I am not able to access Region, Zone and Sales values as var[‘Region’], var[‘Zone’] and var[‘Sales’].

I faced the same issue when I was plotting heatmap where I want to plot Region on x-axis, Zone on y-axis and sum of Sales as a color metric (data point) but not able to pass these values.

Can you help me to perform this or there is another method to deal with these requirements.

Thx,
Imran