Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • pro@slogix.in
  • +91- 81240 01111

Social List

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

Description

Togroup variables to calculate count,average andsumusingpython.

Process

   Read the file.

   Import libraries.

   Use groupby() to group a variables

  Calculate count, average and sum.

Sample Code

#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)

Screenshots
How to group variables in python to calculate count, average, sum
import libraries, import pandas as pd