Skip to main content

dataframe_image

A package to convert Jupyter Notebooks to either PDF or Markdown documents with the following extra functionality not provided directly by nbconvert:

  • Embedding pandas DataFrames into the final PDF or Markdown as they appear in the notebook
  • Downloading the notebook as a PDF appearing exactly as it does in your browser (using the print as PDF feature from chrome)
  • Extracting all images in markdown (inline, reference, attachments, and <img> tags)
  • Allowing the new document to be saved anywhere in your filesystem and correctly linking to resources

Motivation

When converting Jupyter Notebooks to pdf using nbconvert, pandas DataFrames appear as either raw text or as a simple latex table as seen on the left side of the image below.

png

This package was first created to embed DataFrames into pdf and markdown documents as images so that they appear exactly as they do in a Jupyter Notebook, as seen on the right side of the image above. It has since added much more functionality.

Installation

pip install dataframe_image

Usage

There are three different ways to use dataframe_image:

  • Within a Jupyter Notebook
  • As a Python library
  • From the command line

To get access to all of the available options, use it as a library or from the command line. Using it within the notebook allows you to download the notebook as PDF via latex or via the browser.

Within a Jupyter Notebook

Upon installation, two new options will appear in your Jupyter Notebook under File -> Download as -> PDF - DataFrame as Image (via latex) and PDF - DataFrame as Image (via browser). Each option produces a distinctly different output. Using latex, a formal report with numbered sections will be returned. Using the browser, you'll get a near replica of how the notebook appears in your browser.

The conversion process is time consuming as screenshots of each DataFrame will be taken and then embedded into a pdf. A new blank tab will open during the processing. It will appear as nothing is happening. When processing is complete, the document will be downloaded. Converting via browser is significantly faster as it uses chromes built-in print-to-pdf capabilities.

When using this option, the notebook will NOT be executed. Make sure to execute the notebook first.

png

As a Python Library

In a separate Python script, import the dataframe_image package and pass the file name of your notebook to the convert function. By default, a PDF using latex will be produced. Set the use option to 'browser' to get the other version. Using dataframe_image as a Python library provides you with all of the available options, including downloading as a Markdown document.

>>> import dataframe_image as dfi
>>> dfi.convert('path/to/your_notebook.ipynb',
                to='pdf',
                use='latex',
                latex_command=None,
                max_rows=30,
                max_cols=10,
                ss_width=1000,
                ss_height=900,
                resize=1,
                chrome_path=None,
                limit=None,
                document_name=None,
                execute=True,
                save_notebook=False,
                output_dir=None,
                image_dir_name=None
                )

By default, the new file(s) will be saved in the same directory where the notebook resides.

Do not run this command within the same notebook that is being converted.

From the Command Line

The command line tool dataframe_image will be available upon installation with the same options as the convert function from above.

dataframe_image --to=pdf "my notebook with dataframes.ipynb"

Finding Google Chrome

You must have Google Chrome (or Brave) installed in order for dataframe_image to work. The path to Chrome will automatically be found. If Chrome is not in a standard location, set it with the chrome_path parameter.

Publish to Medium (upcoming)

You can publish your notebooks as Medium blog posts by installing the jupyter_to_medium package.

Extras

This package also embeds any images added to markdown cells as attachments (done by dragging and dropping the image) as well as those referenced by HTML <img> tags. It is also able to properly save the pdf/markdown and its images in a directory outside of where it is located.

Dependencies

You must have the following python libraries installed:

Installing LaTeX

It is possible to use dataframe_image without a latex installation as long as you only download pdfs via browser. Consult nbconvert's documentation to learn how to get latex installed correctly on your machine.

Release files for dataframe-image 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataframe-image 0.0.10
File Size Uploaded
dataframe_image-0.0.10.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dataframe-image 0.0.10
File Interpreter ABI Platform
dataframe_image-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 38.6 kB

Release files / dataframe_image-0.0.10.tar.gz

Download URL dataframe_image-0.0.10.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
af61f452653d125e39ca1ce8dc04397c1a6deb7d3935f2bac15f8b3f70e562f0
BLAKE2b-256 checksum
How to use checksums
3aa513d0b69ef5e51a22bb3d50edc24222e06c5ebcfd8a59a0919eb1c64070da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

Release files / dataframe_image-0.0.10-py3-none-any.whl

Download URL dataframe_image-0.0.10-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d29fc7ae10f850de218b44b1601e7884a3758c32462c879a377a21e33cf4d7dc
BLAKE2b-256 checksum
How to use checksums
e56a43a25de76255467f9c2bb32c90fd23032b71be4839168adf5e5af7969a4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

Release history Release notifications | RSS feed

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.5

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

2 release files

0.1.0

2 release files

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

1 release file

0.0.2

3 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page