{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Pandas Crosstab" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# import pandas\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "#Import dataset\n", "data = pd.read_csv('../Data/loan_train.csv', index_col = 'Loan_ID')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th>Loan_Status</th>\n", " <th>N</th>\n", " <th>Y</th>\n", " </tr>\n", " <tr>\n", " <th>Credit_History</th>\n", " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0.0</th>\n", " <td>0.921348</td>\n", " <td>0.078652</td>\n", " </tr>\n", " <tr>\n", " <th>1.0</th>\n", " <td>0.204211</td>\n", " <td>0.795789</td>\n", " </tr>\n", " <tr>\n", " <th>All</th>\n", " <td>0.317376</td>\n", " <td>0.682624</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ "Loan_Status N Y\n", "Credit_History \n", "0.0 0.921348 0.078652\n", "1.0 0.204211 0.795789\n", "All 0.317376 0.682624" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.crosstab(data[\"Credit_History\"],data[\"Loan_Status\"],margins=True, normalize = 'index')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.1" } }, "nbformat": 4, "nbformat_minor": 2 }