Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nbconvert doesn't display styler dataframe from jupyter notebook

I'm using

jupyter nbconvert --to pdf --TemplateExporter.exclude_input=True Scorecard.ipynb

to export my notebook to a pdf. Everything runs fine, but when looking in the pdf the dataframes are shown as

 <pandas.io.formats.style.Styler at 0x1ea7d7910f0>

rather than the nicely colored dataframes in the notebook. Any ideas on how to fix?

Using nbconvert to send to html then using pdfkit to convert works (kind of) The issue with that is the header overlaps the rows if the table spans multiple pages and the rows are split in half if they're at the end of apage

like image 231
user11924246 Avatar asked Aug 15 '19 19:08

user11924246


People also ask

How do you display a Dataframe in Jupyter notebook?

You can visualize a pandas dataframe in Jupyter notebooks by using the display(<dataframe-name>) function. The display() function is supported only on PySpark kernels. The Qviz framework supports 1000 rows and 100 columns.

What is Jupyter Nbconvert?

The nbconvert tool, jupyter nbconvert , converts notebooks to various other formats via Jinja templates. The nbconvert tool allows you to convert an . ipynb notebook file into various static formats including: HTML. LaTeX.

How do I convert a Jupyter notebook to PDF?

The Jupyter Notebook has an option to export the notebook to many formats. It can be accessed by clicking File -> Download as -> PDF via LaTeX (or PDF via HTML - not visible in the screenshot).


1 Answers

I encountered the same error when trying to hide indexes in my Pandas Dataframes with df.style.hide_index().

Unfortunately the Pandas Styling method seems to be based purely on HTML/CSS:

The styling is accomplished using CSS. You write “style functions” that take DataFrames ..., and return like-indexed DataFrames ... with CSS "attribute: value" pairs for the values. These functions can be incrementally passed to the Styler which collects the styles before rendering.

I have not been able to find and method for converting df.style objects into PDF through native latex tables.

There has been some effort on a Styler.to_latex() extension, but the branch died mid-2018.

like image 193
Martin Thøgersen Avatar answered Oct 14 '22 20:10

Martin Thøgersen