pdflatex builder failed to display styled dataframes
See original GitHub issueDescribe the problem
When creating a jupyter book with a styled dataframe as described in the Jupyter Book docs here (https://jupyterbook.org/content/code-outputs.html#library-output-formatting), the dataframe is not displayed with the pdf latex builder and instead we are presented with
<pandas.io.formats.style.Styler at 0x1de96f473d0>
Link to your repository or website
No response
Steps to reproduce
- Create a new Jupyter book with a ipynb containing the following code referenced from (https://jupyterbook.org/content/code-outputs.html#library-output-formatting)
import numpy as np
import pandas as pd
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
axis=1)
df.iloc[3, 3] = np.nan
df.iloc[0, 2] = np.nan
def color_negative_red(val):
"""
Takes a scalar and returns a string with
the css property `'color: red'` for negative
strings, black otherwise.
"""
color = 'red' if val < 0 else 'black'
return 'color: %s' % color
def highlight_max(s):
'''
highlight the maximum in a Series yellow.
'''
is_max = s == s.max()
return ['background-color: yellow' if v else '' for v in is_max]
df.style.\
applymap(color_negative_red).\
apply(highlight_max).\
set_table_attributes('style="font-size: 10px"')
- Build the book as a latexpdf using
jupyter-book build testreport --builder=pdflatex
- Open the PDF and see that where the dataframe should have been, there is instead
<pandas.io.formats.style.Styler at 0x1de96f473d0>
The version of Python you’re using
python 3.8.5
Your operating system
Windows 10
Versions of your packages
Jupyter Book : 0.12.1
External ToC : 0.2.3
MyST-Parser : 0.15.2
MyST-NB : 0.13.1
Sphinx Book Theme : 0.1.7
Jupyter-Cache : 0.4.3
NbClient : 0.5.3
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Bibtex finished with 3 error messages - LaTeX Stack Exchange
I'm in AUCTeX under Win 7. This is the route to follow, isn't it? compile main.tex with pdflatex; launch BibTex on main.
Read more >pyspark show dataframe as table with horizontal scroll in ...
Open the jupyter notebook ../site-packages/notebook/static/style/style.min.css file. Search for white-space: pre-wrap; , and remove it. Save ...
Read more >pandas.DataFrame — pandas 1.5.2 documentation
Return an int representing the number of elements in this object. style. Returns a Styler object. ... Compare to another DataFrame and show...
Read more >Formatting code outputs - Jupyter Book
See the Pandas Styling docs for more information about styling DataFrames, ... By default, the standard output/error streams and text/plain MIME outputs may ......
Read more >Creating PDF Reports with Pandas, Jinja and WeasyPrint
For example, if you want to put two DataFrames on one Excel sheet, you need to ... a fully composed HTML table with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Quick update on this, I’ve found both the seeming cause and a workaround. Once we call
df.style
, we no longer have apd.Dataframe
but rather apd.io.formats.style.Styler
. TheStyler
object does not have_repr_latex_
defined that is required to render it in latex but it does have ato_latex()
method. Which means we can just add the following lines to our code to get it to workNow once we have this, we will need to make sure a few more packages are added to our latex build. This can be done by adding the following lines to our _conf.yml
I think this is the same issue.
https://github.com/executablebooks/jupyter-book/issues/1512
According to pandas, this should be improvded by the 1.4 release, which is currently on the way.