Pandas Pivot Table: Create a Pivot table and find the total sale amount region wise, manager wise, sales man wise
Pandas: Pivot Table Exercise-9 with Solution
Write a Pandas program to create a Pivot table and find the total sale amount region wise, manager wise, sales man wise where Manager = "Douglas". Go to Excel data
Sample Solution:
Python Code :
import pandas as pd
df = pd.read_excel('E:\SaleData.xlsx')
table = pd.pivot_table(df,index=["Region","Manager","SalesMan"], values="Sale_amt")
print(table.query('Manager == ["Douglas"]'))
Sample Output:
Sale_amt Region Manager SalesMan Central Douglas John 41338.666667 East Douglas Karen 16068.000000 West Douglas Michael 33418.000000
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 manager wise, salesman wise total sale and also display the sum of all sale amount at the bottom.
Next: Write a Pandas program to create a Pivot table and find the region wise Television and Home Theater sold.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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://198.211.115.131/python-exercises/pandas/excel/pandas-pivot-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics