w3resource

Pandas Pivot Table: Create a Pivot table and count the manager wise sale and mean value of sale amount

Pandas: Pivot Table Exercise-7 with Solution

Write a Pandas program to create a Pivot table and count the manager wise sale and mean value of sale amount. Go to Excel data

Sample Solution:

Python Code :

import pandas as pd
import numpy as np
df = pd.read_excel('E:\SaleData.xlsx')
print(pd.pivot_table(df,index=["Manager"],values=["Sale_amt"],aggfunc=[np.mean,len]))

Sample Output:

                 mean      len
             Sale_amt Sale_amt
Manager                       
Douglas  29882.000000      8.0
Hermann  30425.708333     12.0
Martha   33749.500000     14.0
Timothy  25446.444444      9.0                                      

Pivot Table:

Salesdata.xlsx:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to create a Pivot table and find the region wise, item wise unit sold.
Next: Write a Pandas program to create a Pivot table and find manager wise, salesman wise total sale and also display the sum of all sale amount at the bottom.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/pandas/excel/pandas-pivot-exercise-7.php