ENH: Styler.to_latex() · Issue #21673 · pandas-dev/pandas (original) (raw)
I have created a branch adding a to_latex
method to Styler
.
It is nowhere near readiness, and in particular:
- supports only cell background color as of now - adding some attributes should be trivial, adding others might be less so
- most importantly, it works on a copy of the dataframe casted
.astype(str)
, which is plain wrong because it discards features such as float formatting. For a good result, a better integration is needed with the code that currently does cell formatting inDataFrame.to_latex
.
This said, if anyone feels like experimenting, it might be slightly better than starting from scratch.
One aspect which I think is useful, even aside from this branch, and might benefit some discussion, is the pair of methods _latex_preserve
and _latex_restore
, which basically replace LaTeX commands so that they are not disturbed by escaping, and then restores them. There might be better way to code this, but I really think this is something we need to implement, and to offer to users who happen to nest LaTeX code in their cells.