Pandas DataFrame aggregate() Method

Get Job-Ready: Data Analysis using Python with 70+ Projects Start Now!!

Program 1

# Advance Data Analysis 
#Aggrigate Functions 
# max(),min(),avg(),count(),sum(),mod(),mean()

import pandas as pd
product=[('Limca',20,'Sanchi'),('Frooti',25,'Amul'),('Milk',10,'BK'),('Water',20,'BK'),
       ('Limca',25,'AK'),('Frooti',20,'SK'),('Milk',28,'BK'),('Water',30,'Sanchi'),
        ('Limca',27,'Sanchi'),('Frooti',29,'AK'),('Milk',25,'Amul'),('Water',45,'Sanchi'),
        ('Water',29,'Amul'),('Limca',40,'DK'),('Frooti',12,'Amul'),('Water',40,'Sanchi')
        ]
#print(product)
df=pd.DataFrame(product,columns=['Product Name','Price','Distributor'])
#print(df)
df1=df.groupby('Product Name')
# for name,rows in df1:
#     print(name)
#     print(rows)
#print(df1['Price'].agg(['max','min']))
#print(df1['Price'].agg(['count']))
#print(df1['Price'].agg(['sum']))
print(df1['Price'].agg(['mean']))

 

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *