Tables with jupyter formatting
Github repo
Jupyter notebooks have really nice table formatting (it doesn't come from pandas). Is there a way to export a pandas table to image, in the style of Jupyter notebook, to .svg
, and without any external libaries? Yes.
Why?
- it's easier to copy and paste a table into Word as an image file rather than enter individual elements
- Jupyter notebook formatting is really nice
- pandas can export to LaTeX fine, as well as HTML with nice formatting, but it doesn't export directly to
.png
or, even better, .svg
. There is a project (dataframe_image) that converts tables to .png
in the style of a Jupyter notebook, but it requires Chrome running in headless mode, and it doesn't export to .svg
.
The Formatting is easy to emulate in .svg
, after all it's just rectangles, lines, and text. For an example see the below - it's not a screenshot of a rendered pandas dataframe, but is an .svg
file made to look like the same thing.
The code in the repo above can process any dataframe in this way, with no external libraries required.
P.S. why .svg
? It's the natural choice for a table - it's high (infinite) resolution, low file size, and supports text highlighting. Also it's just a bunch of rectangles, lines, and text, just like a table.