Pandas Pivot Table: Create a Pivot table and find the region wise Television and Home Theater sold
Pandas: Pivot Table Exercise-10 with Solution
Write a Pandas program to create a Pivot table and find the region wise Television and Home Theater sold. 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", "Item"], values="Units")
print(table.query('Item == ["Television","Home Theater"]'))
Sample Output:
Units Region Item Central Home Theater 53.000000 Television 55.333333 East Home Theater 46.800000 Television 65.000000 West Home Theater 32.000000 Television 44.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 the total sale amount region wise, manager wise, sales man wise.
Next: Write a Pandas program to create a Pivot table and find the maximum sale value of the items.
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://w3resource.com/python-exercises/pandas/excel/pandas-pivot-exercise-10.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics