Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating publication quality tables in python

Tags:

python

tabular

I'd like to create publication quality tables for output as svg or jpg or png images using python.

I'm familiar with the texttable module which produces nice text tables but if I have for example

data = [['Head 1','Head 2','Head 3'],['Sample Set Type 1',12.8,True],['Sample Set Type 2',15.7,False]]

and I wanted to produce something that looked like

table image

Is there a module I can turn to, or can you point me to a process for going about it?

like image 831
Tahnoon Pasha Avatar asked Sep 10 '13 03:09

Tahnoon Pasha


1 Answers

There are large amounts of possibilities for you.

You can convert a Pandas dataframe to Latex as per https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_latex.html

You can also use Tabular to output latex source as per http://en.wikibooks.org/wiki/LaTeX/Tables

You can use ReportLab, as per Python reportlab inserting image into table

You could also just write an HTML table file and style it with css.

with open("example.html", "w") as of:
    of.write("<html><table>")
    for index, row in enumerate(data):
        if index == 0:
             of.write("<th>")
        else:
             of.write("<tr>")

        for cell in row:
             of.write("<td>" + cell + "</td>")
        if index == 0:
             of.write("</th>")
        else:
             of.write("</tr>")

    of.write("</table></html>")

You can do something similar with Latex tables as an output.

like image 167
Jules G.M. Avatar answered Sep 22 '22 17:09

Jules G.M.