Pandas Pivot Table: Create a Pivot table and find the total sale amount region wise, manager wise, sales man wise
9. Filtered Pivot Table for Manager "Douglas"
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:
For more Practice: Solve these Related Problems:
- Write a Pandas program to create a pivot table that calculates total sale amount by region, manager, and salesman, filtering for Manager = "Douglas".
- Write a Pandas program to generate a pivot table and then use boolean indexing to display data where the manager is "Douglas".
- Write a Pandas program to build a pivot table from Salesdata.xlsx and then extract the sub-table corresponding to Manager "Douglas".
- Write a Pandas program to create a pivot table that includes a filter condition to show only records for Manager "Douglas" and summarize sale totals.
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.