A Simple Example¶
Note: This is a (somewhat ugly) export of an Jupyter notebook that can be found in the “examples” folder.
# This is only necessary to execute this notebook from the examples folder.
import sys
import os
sys.path.insert(0, os.path.abspath('..'))
from tableprinter import Tableprinter
# For displaying the HTML output directly in the notebook
from IPython.display import HTML
data = [
{'x': 'a', 'y': 1, 'content': 'Top Left'},
{'x': 'b', 'y': 1, 'content': 'Top Right'},
{'x': 'a', 'y': 2, 'content': 'Bottom Left'},
{'x': 'b', 'y': 2, 'content': 'Bottom Right'}
]
tp = Tableprinter(data, x_dimensions=('x',), y_dimensions=('y',))
Text Output¶
print(tp.as_ascii())
print(tp.as_unicode())
┏━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ ┃ a ┃ b ┃
┣━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
│1 │ Top Left │ Top Right │
│──├─────────────┼──────────────┤
│2 │ Bottom Left │ Bottom Right │
└──┴─────────────┴──────────────┘
HTML Output¶
HTML(tp.as_html())
a | b | |
---|---|---|
1 | Top Left | Top Right |
2 | Bottom Left | Bottom Right |
Note: The produced HTML sets various class
attributes and can
therefore be arbitrarily styled.
LaTeX Output¶
Note: LaTeX output only produces the tabular environment. You probably want to wrap it into a table environment.
print(tp.as_latex())
begin{tabular}{ rcc } toprule multicolumn{ 1 }{c}{ } & a& b\ midrule multirow{ 1 }{*}{1} & Top Left & Top Right\ multirow{ 1 }{*}{2} & Bottom Left & Bottom Right\ bottomrule end{tabular}