Q. Assume that the following data is stored in a dataframe named df1. Write the commands to:


(i) find total sales per state

(ii) find total sales per employee

(iii) find total sales both employee-wise and state-wise

(iv) find mean, median and min sale state-wise

(v) find maximum sale by individual


Name of Employee    Sales    Quarter-State    State
RSahay    125600    1    Delhi
George    235600    1    Tamil Nadu
JayaPriya    213400    1    Kerala
ManilaSahai    189000    1    Haryana
RymaSen    456000    1    West Bengal
ManilaSahai    172000    2    Haryana
JayaPriya    201400    2    Kerala

Answer :-

(i)
pv1 = pd.pivot_table(dfN, index = ['State'], values = ['Sales'], aggfunc = np.sum)

(ii)
pv1 = pd.pivot_table (dfN, index =('Name of Employee'), values = ['Sales'], aggfunc = np.sum)

(iii)
pv1 = pd.pivot_table (dfN, index = ['Name of Employee', 'State'], values = ['Sales'], aggfunc = np.sum)

(iv)
pv1 = pd.pivot_table (dfN, index = ['State'], values = ['Sales'], aggfunc = [np.mean, np.min, np.max])

(v)
pvi = pd.pivot_table (dfN, index = ['Name of Employee'], values = ['Sales'], aggfunc = np.max)

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post