#!/usr/bin/env python # coding: utf-8 # In[1]: from tabipy import Table, TableRow, TableCell, TableHeaderRow # This is a package to simply create tables to be displayed in IPython. The tables are rendered as both HTML and LaTeX, so they work both in the browser and if you convert the notebook to LaTeX. # # The simplest case is a plain grid: # In[2]: Table((4, 1, 8), (9, 7, 3), (5, 2, 6)) # You can add a header row like this: # In[3]: Table(TableHeaderRow('a','b','c'), (1, 2, 3), (2, 4, 6), ) # `Table` also accepts `dict`s (or any mapping) with keys as column headers and values as column contents. The order of columns is undefined unless the mapping is an `OrderedDict`. # In[4]: Table({'a': (1, 2), 'b': (2, 4), 'c': (3, 6)}) # The number of column values (rows) need not be equal: # In[5]: Table({'a': (1, 2), 'b': (2,), 'c': (3, 6)}) # You can build a table incrementally using `Table.append_row()`. If you need it, rows also have an `append_cell()` method. # In[6]: # Computing values t = Table(TableHeaderRow('number', 'square', 'cube')) for x in range(1, 11): t.append_row((x, x**2, x**3)) t # You can style cells with the `bg_colour` and `text_colour` parameters. This only works in HTML for the moment; if you convert the notebook to LaTeX, the colours will be ignored. # In[7]: # Styling determined by code t = Table(TableHeaderRow('divisions', 'result')) num = 55 for x in range(7): if num < 1: resultcell = TableCell(num, bg_colour='DarkBlue', text_colour='white') else: resultcell = TableCell(num) t.append_row((x, resultcell)) num /= 3 t