Skip to content

Instantly share code, notes, and snippets.

@Ayehavgunne
Ayehavgunne / crosstab.py
Created June 18, 2019 20:21 — forked from gregpinero/crosstab.py
Create a cross tab / pivot table in Python
import itertools
def crosstab(rows, columns, col_idx_for_columns, lst_col_idx_for_rows, value_col_idx, fill_val, format_func=None):
"""Take col_idx_to_cross_tab and make its unique values be new columns at the end filled with
value_col_idx values. col idx arguments are 0 based.
This is basically a simplified pivot table creator with the limitations that you can only have one field in the columns
and there is no aggregation.