#!/usr/bin/env python # coding: utf-8 # # ipy_table Reference # # The home page for ipy_table is at [epmoyer.github.com/ipy_table/](http://epmoyer.github.com/ipy_table/) # # ipy_table is maintained at [github.com/epmoyer/ipy_table](https://github.com/epmoyer/ipy_table) # In[1]: import add_parent_to_path # ## Table Creation # To create a table call make_table on an array (a list of equal sized lists) or a ``numpy.ndarray``. # # ``make_table()`` creates a table in interactive mode. Subsequent calls to modify styles (e.g. ``apply_theme()``, ``set_cell_style()``, etc.) will re-render the table with the new style modifications. # In[2]: from ipy_table import * example_table = [[i for i in range(j,j+4)] for j in range(0,30,10)] make_table(example_table) # ## Built-in Styles # ipy_table implements three pre-defined table styles (basic, basic_left, and basic_both) which provide bold gray headers and alternating colored rows for three different header configurations. # In[3]: make_table(example_table) apply_theme('basic') # In[4]: make_table(example_table) apply_theme('basic_left') # In[5]: import copy example_table2 = copy.deepcopy(example_table) # Copy the example table example_table2[0][0] = '' # Clear the contents of the upper left corner cell make_table(example_table2) apply_theme('basic_both') # ## set_cell_style() # Sets the style of a single cell. For a list of the available style options, see **Syle Options** below. # In[6]: make_table(example_table) set_cell_style(1, 2, color='red') # ## set_row_style() # Sets the style for a row of cells. For a list of the available style options, see **Syle Options** below. # In[7]: make_table(example_table) set_row_style(0, color='lightGreen') # ## set_column_style() # Sets the style for a column of cells. For a list of the available style options, see **Syle Options** below. # In[8]: make_table(example_table) set_column_style(1, color='lightBlue') # ## set_global_style() # Sets the style for all cells. For a list of the available style options, see **Syle Options** below. # In[9]: make_table(example_table) set_global_style(color='Pink') # ## Style options # ### bold # In[10]: make_table(example_table) set_row_style(1, bold=True) # ### italic # In[11]: make_table(example_table) set_row_style(1, italic=True) # ### color # Sets background cell color by name. The color name can be any any standard web/X11 color name. For a list see http://en.wikipedia.org/wiki/Web_colors # In[12]: make_table(example_table) set_row_style(1, color='Orange') # ### thick_border # Accepts a comma delimited list of cell edges, which may be any of: left, top, right, bottom. You can also speify 'all' to include all edges. # In[13]: make_table(example_table) set_cell_style(0,0, thick_border='left,top') set_cell_style(2,3, thick_border='right,bottom') # In[14]: make_table(example_table) set_row_style(1, thick_border='all') # ### no_border # Accepts a comma delimited list of cell edges, which may be any of: left, top, right, bottom. You can also speify 'all' to include all edges. # In[15]: make_table(example_table) set_cell_style(0,0, no_border='left,top') set_cell_style(2,3, no_border='right,bottom') # In[16]: make_table(example_table) set_row_style(1, no_border='all') # ### row_span # In[17]: make_table(example_table) set_cell_style(0, 0, row_span=3) # ### column_span # In[18]: make_table(example_table) set_cell_style(1,1, column_span=3) # ### width # Sets the cell width in pixels. # In[19]: make_table(example_table) set_cell_style(0,0, width=100) # ### align # Sets the cell alignment. Accpets any of: left, right, center. # In[20]: make_table(example_table) set_cell_style(0, 0, width='100') set_cell_style(0, 0, align='right') set_cell_style(1, 0, align='center') # ### wrap # Turns text wrapping on or off. By default wraping is off. # In[21]: example_table2 = copy.deepcopy(example_table) example_table2[0][0] = 'This cell has wrap set' example_table2[0][1] = 'This cell does not have wrap set' make_table(example_table2) set_cell_style(0, 0, width=50,wrap=True) set_cell_style(0, 1, width=50) # ### float_format # Sets the display format for floating point values. # # The float format string is a standard Python "%" format string (and should contain one and only one %f reference). See http://docs.python.org/2/library/stdtypes.html#string-formatting-operations # # The float format only affects cells that contain ``float`` or ``numpy.float64`` data types, so you can use set_global_style to set a global floating point format and only those cells containing floating point data will be affected. # # The default float format is '%0.4f'. # In[22]: from ipy_table import * example_table2 = [[i + float(i)/100.0 + i/10000.0 for i in range(j,j+4)] for j in range(0,30,10)] make_table(example_table2) set_cell_style(0, 0, float_format='%0.1f') set_cell_style(1, 0, float_format='%0.6f') set_cell_style(2, 0, float_format='$%0.2f') # ## Class interface # In[23]: t = IpyTable(example_table) t.set_cell_style(1, 1, color='DarkCyan') # In[24]: t # ## Interactive interface with manual render # In[25]: make_table(example_table, interactive=False) # In[26]: set_row_style(1,color='yellow') # In[27]: render() # ## HTML Text Representation # The HTML text representation of the current table can be obtained by calling ``render()._repr_html_()`` # In[28]: render()._repr_html_() # ## Tabulate # Use ``tabulate(list, n)`` to display a list (not an array) of data in a table with n columns. # In[29]: tabulate(range(20), 6) # ``tabulate()`` creates a table object just like ``make_table()``, so the same style operations can be applied. # In[30]: set_cell_style(1, 2, color='yellow') # ## Version # In[31]: import ipy_table as ipt ipt.__version__