Pandas Pivot Table: Create a Pivot table and find the item wise unit 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:
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 region wise total sale.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics