In [1]:
import pandas as pd
In [2]:
df = pd.read_csv('data/src/titanic_train.csv', index_col=0).drop(['Name', 'Ticket', 'SibSp', 'Parch'], axis=1)
In [3]:
print(df.head())
In [4]:
print(pd.crosstab(df['Sex'], df['Pclass']))
In [5]:
print(type(pd.crosstab(df['Sex'], df['Pclass'])))
In [6]:
print(pd.crosstab([df['Sex'], df['Survived']], [df['Pclass'], df['Embarked']]))
In [7]:
print(pd.crosstab([df['Sex'], df['Survived']], [df['Pclass'], df['Embarked']],
margins=True))
In [8]:
print(pd.crosstab([df['Sex'], df['Survived']], [df['Pclass'], df['Embarked']],
margins=True, margins_name='Total'))
In [9]:
print(pd.crosstab(df['Sex'], df['Pclass'], margins=True, normalize=True))
In [10]:
print(pd.crosstab(df['Sex'], df['Pclass'], margins=True, normalize='index'))
In [11]:
print(pd.crosstab(df['Sex'], df['Pclass'], margins=True, normalize='columns'))
In [12]:
# print(pd.crosstab(df['Sex'], [df['Pclass'], df['Embarked']],
# margins=True, normalize=True))
# TypeError: Expected tuple, got str
In [13]:
print(pd.crosstab(df['Sex'], [df['Pclass'], df['Embarked']],
margins=True, normalize='index'))
In [14]:
# print(pd.crosstab(df['Sex'], [df['Pclass'], df['Embarked']],
# margins=True, normalize='columns'))
# ValueError: Length of new names must be 1, got 2
In [15]:
print(pd.crosstab(df['Sex'], [df['Pclass'], df['Embarked']], normalize=True))
In [16]:
print(pd.crosstab(df['Sex'], [df['Pclass'], df['Embarked']], normalize='index'))
In [17]:
print(pd.crosstab(df['Sex'], [df['Pclass'], df['Embarked']], normalize='columns'))