Skip to content

Instantly share code, notes, and snippets.

@ritshpatidar
Last active October 21, 2019 12:22
Show Gist options
  • Save ritshpatidar/f0516e62318d798579326ccf2fca7222 to your computer and use it in GitHub Desktop.
Save ritshpatidar/f0516e62318d798579326ccf2fca7222 to your computer and use it in GitHub Desktop.
#How to get contingency table
import pandas as pd
#Read the csv data file
data = pd.read_csv('train.csv')
#Getting 'Embarked' feature values without null value
embarked = data[pd.notnull(data['Embarked'])]['Embarked']
#Getting 'Survival' feature values correponding to 'Embarked'
survived = data[pd.notnull(data['Embarked'])]['Survived']
#Creating contingency table using pd.crosstab() function
con_table = pd.crosstab(embarked, survived)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment