In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from pandas import DataFrame, Series

In [3]:
data = DataFrame({'Sample': range(1, 11),
                 'Gender': ['Female', 'Male', 'Female', 'Male', 'Male',
                           'Male', 'Female', 'Female', 'Male', 'Female'],
                 'Mandedness': ['Right-handed', 'Left-handed',
                               'Right-handed', 'Right-handed', 'Left-handed',
                               'Right-handed', 'Right-handed', 'Left-handed',
                               'Right-handed', 'Right-handed']})
data


Out[3]:
Gender Mandedness Sample
0 Female Right-handed 1
1 Male Left-handed 2
2 Female Right-handed 3
3 Male Right-handed 4
4 Male Left-handed 5
5 Male Right-handed 6
6 Female Right-handed 7
7 Female Left-handed 8
8 Male Right-handed 9
9 Female Right-handed 10

In [9]:
data.pivot_table(index='Gender',columns='Mandedness', aggfunc='count',
                margins=True)


Out[9]:
Sample
Mandedness Left-handed Right-handed All
Gender
Female 1.0 4.0 5.0
Male 2.0 3.0 5.0
All 3.0 7.0 10.0

In [12]:
pd.crosstab(data.Gender, data.Mandedness, margins=True)


Out[12]:
Mandedness Left-handed Right-handed All
Gender
Female 1 4 5
Male 2 3 5
All 3 7 10

In [13]:
pd.crosstab?

In [ ]: