Export pandas Styled table to image file

后端 未结 1 2049
执念已碎
执念已碎 2020-12-09 08:45

The code below when run in jupyter notebook renders a table with a colour gradient format that I would like to export to an image file.

The resulting \'styled_table

相关标签:
1条回答
  • 2020-12-09 09:28

    As mentioned in the comments, you can use the render property to obtain an HTML of the styled table:

    html = styled_table.render()
    

    You can then use a package that converts html to an image. For example, IMGKit: Python library of HTML to IMG wrapper. Bear in mind that this solution requires the installation of wkhtmltopdf, a command line tool to render HTML into PDF and various image formats. It is all described in the IMGKit page.

    Once you have that, the rest is straightforward:

    import imgkit
    imgkit.from_string(html, 'styled_table.png')
    
    0 讨论(0)
提交回复
热议问题