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 create cross table using python?

Description

To create cross table for given datam set in python.

Process

   Import libraries.

   Read input file.

  Defining the input variable.

   Two way cross tab.

   Three way cross tab.

Sample Code

#import libraries

import pandas as pd

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

/Sathish/Pythonfiles/Employee.xlsx’)

print(“Actual data is\n”,data)

#create data frame

df=pd.DataFrame(data)

print(“Two way cross tab\n”)

#two way cross tab

a=pd.crosstab(df.salary, df.dept,margins=True)

print(a)

print(“Three way cross tab\n”)

#three way cross tab

b=pd.crosstab([df.dept, df.age],df.salary, margins=True)

print(b)

Screenshots
create cross table using python
import pandas as pd
two way cross tab