6

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tahnoon Pasha
  • 5,848
  • 14
  • 49
  • 75

1 Answers1

5

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.

Jules G.M.
  • 3,624
  • 1
  • 21
  • 35