How to group variables in python to calculate count, average, sum?

Description

Togroup variables to calculate count,average andsumusingpython.

   Read the file.

   Import libraries.

   Use groupby() to group a variables

  Calculate count, average and sum.

#import libraries

import pandas as pd

#read the file

data=pd.read_excel(‘/home/soft27/soft27

/Sathish/Pythonfiles/Employee.xlsx’)

#create the data frame

df=pd.DataFrame(data)

#grouping the rows

test=df.groupby([‘dept’])

test1=df.groupby([‘salary’])

#calculate count,average and sum

t=test.describe()

t1=test1.describe()

#printing the output

print(t)

print(t1)

Leave Comment

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

clear formSubmit