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']))
We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

