{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ipy_table Reference\n", "\n", "The home page for ipy_table is at [epmoyer.github.com/ipy_table/](http://epmoyer.github.com/ipy_table/)\n", "\n", "ipy_table is maintained at [github.com/epmoyer/ipy_table](https://github.com/epmoyer/ipy_table)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import add_parent_to_path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Table Creation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To create a table call make_table on an array (a list of equal sized lists) or a ``numpy.ndarray``. \n", "\n", "``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." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from ipy_table import *\n", "example_table = [[i for i in range(j,j+4)] for j in range(0,30,10)]\n", "make_table(example_table)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Built-in Styles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "apply_theme('basic')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "apply_theme('basic_left')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import copy\n", "example_table2 = copy.deepcopy(example_table) # Copy the example table\n", "example_table2[0][0] = '' # Clear the contents of the upper left corner cell\n", "make_table(example_table2)\n", "apply_theme('basic_both')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## set_cell_style()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the style of a single cell. For a list of the available style options, see **Syle Options** below." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_cell_style(1, 2, color='red')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## set_row_style()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the style for a row of cells. For a list of the available style options, see **Syle Options** below." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_row_style(0, color='lightGreen')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## set_column_style()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the style for a column of cells. For a list of the available style options, see **Syle Options** below." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_column_style(1, color='lightBlue')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## set_global_style()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the style for all cells. For a list of the available style options, see **Syle Options** below." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_global_style(color='Pink')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Style options" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### bold" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_row_style(1, bold=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### italic" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_row_style(1, italic=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### color" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_row_style(1, color='Orange')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### thick_border" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_cell_style(0,0, thick_border='left,top')\n", "set_cell_style(2,3, thick_border='right,bottom')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_row_style(1, thick_border='all')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### no_border" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_cell_style(0,0, no_border='left,top')\n", "set_cell_style(2,3, no_border='right,bottom')" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_row_style(1, no_border='all')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### row_span" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
111213
212223
" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_cell_style(0, 0, row_span=3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### column_span" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
1011
20212223
" ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_cell_style(1,1, column_span=3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### width" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the cell width in pixels." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_cell_style(0,0, width=100)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### align" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the cell alignment. Accpets any of: left, right, center." ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_table(example_table)\n", "set_cell_style(0, 0, width='100')\n", "set_cell_style(0, 0, align='right')\n", "set_cell_style(1, 0, align='center')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### wrap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Turns text wrapping on or off. By default wraping is off." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
This cell has wrap setThis cell does not have wrap set23
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "example_table2 = copy.deepcopy(example_table)\n", "example_table2[0][0] = 'This cell has wrap set' \n", "example_table2[0][1] = 'This cell does not have wrap set'\n", "make_table(example_table2)\n", "set_cell_style(0, 0, width=50,wrap=True)\n", "set_cell_style(0, 1, width=50)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### float_format" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sets the display format for floating point values. \n", "\n", "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\n", "\n", "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. \n", "\n", "The default float format is '%0.4f'." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0.01.01012.02023.0303
10.10100011.111112.121213.1313
$20.2021.212122.222223.2323
" ], "text/plain": [ "" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from ipy_table import *\n", "example_table2 = [[i + float(i)/100.0 + i/10000.0 for i in range(j,j+4)] for j in range(0,30,10)]\n", "make_table(example_table2)\n", "set_cell_style(0, 0, float_format='%0.1f')\n", "set_cell_style(1, 0, float_format='%0.6f')\n", "set_cell_style(2, 0, float_format='$%0.2f')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Class interface" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": true }, "outputs": [], "source": [ "t = IpyTable(example_table)\n", "t.set_cell_style(1, 1, color='DarkCyan')" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interactive interface with manual render" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": true }, "outputs": [], "source": [ "make_table(example_table, interactive=False)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": true }, "outputs": [], "source": [ "set_row_style(1,color='yellow')" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
0123
10111213
20212223
" ], "text/plain": [ "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "render()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## HTML Text Representation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The HTML text representation of the current table can be obtained by calling ``render()._repr_html_()``" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'
0123
10111213
20212223
'" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "render()._repr_html_()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tabulate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use ``tabulate(list, n)`` to display a list (not an array) of data in a table with n columns. " ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
012345
67891011
121314151617
1819
" ], "text/plain": [ "" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tabulate(range(20), 6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``tabulate()`` creates a table object just like ``make_table()``, so the same style operations can be applied." ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
012345
67891011
121314151617
1819
" ], "text/plain": [ "" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "set_cell_style(1, 2, color='yellow')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Version" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'1.15.0'" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import ipy_table as ipt\n", "ipt.__version__" ] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 1 }