Introduction

ipy_table is a supporting module for Jupyter Notebooks which makes it easy to create richly formatted data tables.

The home page for ipy_table is at epmoyer.github.com/ipy_table/

ipy_table is maintained at github.com/epmoyer/ipy_table

In [1]:
import add_parent_to_path

Example

To create a table in interactive mode, import ipy_table and call make_table() on an array.

Notes:

  • ipy_table can accept either a "native" array (a list of equal-length lists) or a numpy.ndarray.
  • Arrays passed to ipy_table typically contain integers, floats or strings, but in general they can contain other object types and ipy_table will render the result of calling str() on those objects.
In [2]:
from ipy_table import *
planets = [
    ['Planet', 'Mass (kg)', 'Diameter (km)'],
    ['Mercury', 3.3022E23, 4879], 
    ['Venus', 4.896E24, 12104],
    ['Earth', 5.972E24, 12735],
    ['Mars', 6.4191E23, 6772]];
make_table(planets)
Out[2]:
PlanetMass (kg)Diameter (km)
Mercury330219999999999996854272.00004879
Venus4896000000000000201326592.000012104
Earth5972000000000000327155712.000012735
Mars641910000000000065536000.00006772

The make_table() interface is interactive, so after calling make_table() we can call style formatting commands to modify the current table format. Here we'll apply the "basic" table theme.

Note: Use "basic_left" for tables with row headers. Use "basic_both" for tables with row and coulmn headers.

In [3]:
apply_theme('basic')
Out[3]:
PlanetMass (kg)Diameter (km)
Mercury330219999999999996854272.00004879
Venus4896000000000000201326592.000012104
Earth5972000000000000327155712.000012735
Mars641910000000000065536000.00006772

The Mass values are being fully expanded. By default ipy_table formats floating point numbers using the Python formatting string "%0.4f". We can override that by setting the float_format parameter.

In [4]:
set_global_style(float_format='%0.3E')
Out[4]:
PlanetMass (kg)Diameter (km)
Mercury3.302E+234879
Venus4.896E+2412104
Earth5.972E+2412735
Mars6.419E+236772

All cell formatting is dynamic. Custom formatting can be applied by calling set_<global, row, column, cell>_style().

In [5]:
set_row_style(3,color='yellow')
Out[5]:
PlanetMass (kg)Diameter (km)
Mercury3.302E+234879
Venus4.896E+2412104
Earth5.972E+2412735
Mars6.419E+236772

For documentation on all ipy_table commands, see the ipy_table reference notebook (ipy_table-Reference.ipynb)

In [ ]: