在python中创建发布质量表

Tah*_*sha 6 python tabular

我想使用python创建输出为svg或jpg或png图像的出版质量表.

我熟悉texttable模块,它生成了很好的文本表,但是如果我有的话

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

我想制作一些看起来像的东西

表图像

是否有一个我可以转向的模块,或者你能指出我的流程吗?

Jul*_*.M. 5

您有很多可能性。

您可以按照https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_latex.html将 Pandas 数据框转换为 Latex

您还可以使用表格输出乳胶源,按照http://en.wikibooks.org/wiki/LaTeX/Tables

您可以使用 ReportLab,按照Python reportlab 将图像插入表中

您也可以只编写一个 HTML 表格文件并使用 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>")
Run Code Online (Sandbox Code Playgroud)

您可以使用 Latex 表作为输出执行类似的操作。