'Print data for all statistics as a csv table.'

def print_csv(self, table, column_ids, stats):

    writer = agate.csv.writer(self.output_file)
    header = (['column_id', 'column_name'] + [op_name for op_name in OPERATIONS.keys()])
    writer.writerow(header)
    for column_id in column_ids:
        column_name = table.column_names[column_id]
        column_stats = stats[column_id]
        output_row = [(column_id + 1), column_name]
        for (op_name, op_data) in OPERATIONS.items():
            if (column_stats[op_name] is None):
                output_row.append(None)
                continue
            if (op_name == 'freq'):
                value = ',    '.join([six.text_type(row[column_name]) for row in column_stats['freq']])
            else:
                value = column_stats[op_name]
            output_row.append(value)
        writer.writerow(output_row)
