astanin / python-tabulate

Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate.
https://pypi.org/project/tabulate/
MIT License
2.08k stars 162 forks source link

A "matrix" table format #286

Open alugowski opened 1 year ago

alugowski commented 1 year ago

May I suggest adding a "matrix" table format. I'm using this one to render sparse matrices to text and it works quite well:

TableFormat(
    lineabove=Line("┌", " ", " ", "┐"),
    linebelowheader=Line("┌", " ", " ", "┐"),
    linebetweenrows=None,
    linebelow=Line("└", " ", " ", "┘"),
    headerrow=DataRow(" ", " ", " "),
    datarow=DataRow("│", " ", "│"),
    padding=1,
    with_header_hide=["lineabove"],
)

Example output:

┌           ┐
│     3   2 │
│ 9   6     │
│     3   1 │
│ 0   5     │
└           ┘
   0     1     2     3     4     5     6
┌                                         ┐
│ 10     2          40    -5          24  │
└                                         ┘

edit: slight update to also support headers as matrix column labels