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
import add_parent_to_path
To create a table in interactive mode, import ipy_table and call make_table()
on an array.
Notes:
numpy.ndarray
.str()
on those objects.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)
Planet | Mass (kg) | Diameter (km) |
Mercury | 330219999999999996854272.0000 | 4879 |
Venus | 4896000000000000201326592.0000 | 12104 |
Earth | 5972000000000000327155712.0000 | 12735 |
Mars | 641910000000000065536000.0000 | 6772 |
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.
apply_theme('basic')
Planet | Mass (kg) | Diameter (km) |
Mercury | 330219999999999996854272.0000 | 4879 |
Venus | 4896000000000000201326592.0000 | 12104 |
Earth | 5972000000000000327155712.0000 | 12735 |
Mars | 641910000000000065536000.0000 | 6772 |
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.
set_global_style(float_format='%0.3E')
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 |
All cell formatting is dynamic. Custom formatting can be applied by calling set_<global, row, column, cell>_style()
.
set_row_style(3,color='yellow')
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 |
For documentation on all ipy_table commands, see the ipy_table reference notebook (ipy_table-Reference.ipynb)