GithubHelp home page GithubHelp logo

tinloaf / tableprinter Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 1.0 303 KB

Yet another python table printer. This one outputs to HTML, LaTeX and ASCII. It can deal with hierarchical rows / columns, output in color, …

License: MIT License

Python 100.00%
python3 table

tableprinter's Introduction

Tableprinter

Tableprinter is a small python module that allows you to print your data in tables, be it as ASCII table, HTML table or LaTeX tabular. It allows for hierarchical columns and rows (see the hierarchical example below). To jump right in, you can have a look at the examples below, or you can read the documentation.

Examples

Data is passed to tableprinter as a list of dictionaries. Each dictionary represents one cell of your table, and must contain fields that specify the content of the table, as well as which row and column the cell should be in. More options can be specified for each cell, which you can find in the documentation.

A simple first example

Note: this is a (somewhat ugly) export of a notebook that can be found in the examples folder.

# This is only necessary to execute this notebook from the examples folder.
import sys
import os
sys.path.insert(0, os.path.abspath('..'))

from tableprinter import Tableprinter

# For displaying the HTML output directly in the notebook
from IPython.display import HTML
data = [
    {'x': 'a', 'y': 1, 'content': 'Top Left'},
    {'x': 'b', 'y': 1, 'content': 'Top Right'},
    {'x': 'a', 'y': 2, 'content': 'Bottom Left'},
    {'x': 'b', 'y': 2, 'content': 'Bottom Right'}
]
tp = Tableprinter(data, x_dimensions=('x',), y_dimensions=('y',))

Text Output

print(tp.as_ascii())
#==#=============#==============#
|  |      a      |      b       |
#==#=============#==============#
|1 |  Top Left   |  Top Right   |
|--+-------------+--------------+
|2 | Bottom Left | Bottom Right |
+--+-------------+--------------+
print(tp.as_unicode())
┏━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃  ┃      a      ┃      b       ┃
┣━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━┫
│1 │  Top Left   │  Top Right   │
│──├─────────────┼──────────────┤
│2 │ Bottom Left │ Bottom Right │
└──┴─────────────┴──────────────┘

HTML Output

HTML(tp.as_html())
a
b
1Top LeftTop Right
2Bottom LeftBottom Right

Note: The produced HTML sets various class attributes and can therefore be arbitrarily styled.

LaTeX Output

Note: LaTeX output only produces the tabular environment. You probably want to wrap it into a table environment.

print(tp.as_latex())
\begin{tabular}{ rcc }
\toprule
\multicolumn{ 1 }{c}{  } & a& b\\

\midrule
\multirow{ 1 }{*}{1} & Top Left & Top Right\\
\multirow{ 1 }{*}{2} & Bottom Left & Bottom Right\\

\bottomrule
\end{tabular}

tableprinter's People

Contributors

tinloaf avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

booeysays

tableprinter's Issues

Automated test suite

It would be helpful to have an automated test suite, to check this works correctly on new versions of Python, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.