Pandas Pivot Table: Create a Pivot table and count the manager wise sale and mean value of sale amount
7. Manager-Wise Sale Count and Mean Sale Amount
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:
For more Practice: Solve these Related Problems:
- Write a Pandas program to create a pivot table that counts the number of sales per manager and calculates the mean sale amount.
- Write a Pandas program to generate a pivot table from Salesdata.xlsx that aggregates sales count and average sale amount grouped by manager.
- Write a Pandas program to build a pivot table summarizing manager-wise sale frequencies and their corresponding mean sale values.
- Write a Pandas program to create a pivot table to compute both the count of sales and the mean sale amount for each manager.
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.