How to create cross table using python?

Description

To create cross table for given data
set in python.

  • Import libraries.
  • Read input file.
  • Defining the input variable.
  • Two way cross tab.
  • Three way cross tab.

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

Leave Comment

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

clear formSubmit