Here are some examples of frequency tables in python using the SAS buytest data set.

### One way tables:

#### Count based

pd.crosstab(index=df['Age in years'], columns='Yr Incoe in thous.')

Which produces data like this

#### Frequency

We can calculate a frequency distribution by dividing by the sum or the values column

one_way_freq = one_way/one_way.sum()

Which produces data like this

### Two way tables

#### Count based

For two way, or contingency tables, we do this

two_way = pd.crosstab(index = df['F or M'], columns=df['Climate code for residence, 10, 20, 30']) two_way.columns = [10, 20, 30] two_way.index = ['F', 'M'] two_way

Which produces this:

or this if you want marginal totals

#### Frequency based

For frequency based cell values, do this:

two_way_freq = two_way/two_way.ix["Column_total","Row_total"] two_way_freq

Which produces this:

You can also add more dimensions

high_dim = pd.crosstab(index = [df['1 if product return in past 24mo, 0 otherwise'], df['F or M']], columns=[df['Climate code for residence, 10, 20, 30'], df['1 if Married, 0 otherwise']], margins=True)

To get something like this:

There are more examples and explanations here http://hamelg.blogspot.com.au/2015/11/python-for-data-analysis-part-19_17.html