How to make a pandas crosstab with percentages?

From Pandas 0.18.1 onwards, there’s a normalize option:

In [1]: pd.crosstab(df.A,df.B, normalize="index")
Out[1]:

B              A           B           C
A           
one     0.333333    0.333333    0.333333
three   0.333333    0.333333    0.333333
two     0.333333    0.333333    0.333333

Where you can normalise across either all, index (rows), or columns.

More details are available in the documentation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)