Pandas Pivot Table: Create a Pivot table and find the item wise unit sold
4. Item-Wise Units Sold
Write a Pandas program to create a Pivot table and find the item wise unit sold. 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=["Item"], values="Units", aggfunc=np.sum))
Sample Output:
Units Item Cell Phone 278 Desk 10 Home Theater 722 Television 716 Video Games 395
Pivot Table:
Salesdata.xlsx:
For more Practice: Solve these Related Problems:
- Write a Pandas program to create a pivot table that calculates the total units sold for each item.
- Write a Pandas program to generate a pivot table with items as the index and units sold as values, using sum as the aggregation.
- Write a Pandas program to build a pivot table from Salesdata.xlsx that shows the unit sold per item and then sort the items by units sold.
- Write a Pandas program to create a pivot table to compute item-wise unit sales and then filter the results for items with units sold above a threshold.
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 region wise total sale.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.