# Contingency Table in Python

## Contingency Table in Python

Estimations like mean, median, standard deviation, and variance are very much useful in case of the univariate data analysis. But in the case of bivariate analysis(comparing two variables) correlation comes into play.

Contingency Table is one of the techniques for exploring two or even more variables. It is basically a tally of counts between two or more categorical variables.

 `import` `numpy as np` `import` `pandas as pd` `import` `matplotlib as plt`

 `data ``=` `pd.read_csv(``"loan_status.csv"``)` ` ` `print` `(data.head(``10``))`

Output:

Describe Data

 `data.describe()`

Output:

Data Info

 `data.info()`

Output:

Data Types

 `# data types of feature/attributes ` `# in the data` `data.dtypes`

Output:

Code #1: Contingency Table showing correlation between Grades and loan status.

 `data_crosstab ``=` `pd.crosstab(data[``'grade'``],` `                            ``data[``'loan_status'``], ` `                               ``margins ``=` `False``)` `print``(data_crosstab)`

Output:

Code #2: Contingency Table showing correlation between Purpose and loan status.

 `data_crosstab ``=` `pd.crosstab(data[``'purpose'``], ` `                            ``data[``'loan_status'``],` `                                ``margins ``=` `False``)` `print``(data_crosstab)`

Output:

Code #3: Contingency Table showing correlation between Grades+Purpose and loan status.

 `data_crosstab ``=` `pd.crosstab([data.grade, data.purpose], ` `                             ``data.loan_status, margins ``=` `False``)` `print``(data_crosstab)`

Output:

So as in the code, Contingency Tables are giving clear correlation values between two and more variables. Thus making it much more useful to understand the data for further information extraction.
.

Last Updated on October 19, 2021 by admin

## Python | Pandas Index.drop()Python | Pandas Index.drop()

Python | Pandas Index.drop() Python is a great language for doing data analysis, primarily because

## Count distinct in Pandas aggregationCount distinct in Pandas aggregation

Count distinct in Pandas aggregation In this article, let’s see how we can count distinct

## Pandas GroupByPandas GroupBy

Pandas Groupby   Using Pandas Groupby, we can create a grouping of categories and apply

## Pandas dataframe.div()Pandas dataframe.div()

Python | Pandas dataframe.div() Python is a great language for doing data analysis, primarily because

## Python | Pandas Series/Dataframe.any()Python | Pandas Series/Dataframe.any()

Python | Pandas Series/Dataframe.any() Pandas any() method is applicable both on Series and Dataframe. It checks whether any value in

## Python | Pandas dataframe.filter()Python | Pandas dataframe.filter()

Pandas dataframe.filter() function is used to Subset rows or columns of dataframe according to labels

## Get the data type of column in Pandas – PythonGet the data type of column in Pandas – Python

Get the data type of column in Pandas – Python Let’s see how to get

## How to import excel file and find a specific column using Pandas?How to import excel file and find a specific column using Pandas?

How to import excel file and find a specific column using Pandas? In this article,