{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction\n",
"ipy_table is a supporting module for Jupyter Notebooks which makes it easy to create richly formatted data tables.\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": [
"# Example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To create a table in interactive mode, import ipy_table and call ``make_table()`` on an array.\n",
"\n",
"Notes:\n",
"\n",
"* ipy_table can accept either a \"native\" array (a list of equal-length lists) or a ``numpy.ndarray``. \n",
"* 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."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
Planet | Mass (kg) | Diameter (km) |
Mercury | 330219999999999996854272.0000 | 4879 |
Venus | 4896000000000000201326592.0000 | 12104 |
Earth | 5972000000000000327155712.0000 | 12735 |
Mars | 641910000000000065536000.0000 | 6772 |
"
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ipy_table import *\n",
"planets = [\n",
" ['Planet', 'Mass (kg)', 'Diameter (km)'],\n",
" ['Mercury', 3.3022E23, 4879], \n",
" ['Venus', 4.896E24, 12104],\n",
" ['Earth', 5.972E24, 12735],\n",
" ['Mars', 6.4191E23, 6772]];\n",
"make_table(planets)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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.\n",
"\n",
"Note: Use \"basic_left\" for tables with row headers. Use \"basic_both\" for tables with row and coulmn headers."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Planet | Mass (kg) | Diameter (km) |
Mercury | 330219999999999996854272.0000 | 4879 |
Venus | 4896000000000000201326592.0000 | 12104 |
Earth | 5972000000000000327155712.0000 | 12735 |
Mars | 641910000000000065536000.0000 | 6772 |
"
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"apply_theme('basic')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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.\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Planet | Mass (kg) | Diameter (km) |
Mercury | 3.302E+23 | 4879 |
Venus | 4.896E+24 | 12104 |
Earth | 5.972E+24 | 12735 |
Mars | 6.419E+23 | 6772 |
"
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_global_style(float_format='%0.3E')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All cell formatting is dynamic. Custom formatting can be applied by calling ``set__style()``."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Planet | Mass (kg) | Diameter (km) |
Mercury | 3.302E+23 | 4879 |
Venus | 4.896E+24 | 12104 |
Earth | 5.972E+24 | 12735 |
Mars | 6.419E+23 | 6772 |
"
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_row_style(3,color='yellow')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For documentation on all ipy_table commands, see the ipy_table reference notebook (ipy_table-Reference.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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
}