w3resource

Pandas Pivot Table: Create a Pivot table and find the total sale amount region wise, manager wise, sales man wise

Pandas: Pivot Table Exercise-3 with Solution

Write a Pandas program to create a Pivot table and find the total sale amount region wise, manager wise, sales man wise. Go to Excel data

Sample Solution:

Python Code :

import numpy as np
import pandas as pd
df = pd.read_excel('E:\SaleData.xlsx')
print(pd.pivot_table(df,index=["Region","Manager","SalesMan"], values="Sale_amt", aggfunc=np.sum))

Sample Output:

                           Sale_amt
Region  Manager SalesMan           
Central Douglas John       124016.0
        Hermann Luis       206373.0
                Shelli      33698.0
                Sigal      125037.5
        Martha  Steven     199690.0
        Timothy David      140955.0
East    Douglas Karen       48204.0
        Martha  Alexander  236703.0
                Diana       36100.0
West    Douglas Michael     66836.0
        Timothy Stephen     88063.0                                       

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.
Next: Write a Pandas program to create a Pivot table and find the item wise unit sold.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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-3.php