Skip to main content

Embed pandas DataFrames as images in pdf and markdown files when converting from Jupyter Notebooks

Project description

dataframe_image

A package to embed pandas DataFrames as images when converting Jupyter Notebooks to pdf or markdown documents.

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 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.

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 uses the default options and downloads a pdf.

Within a Jupyter Notebook

Upon installation, a new option will appear in your Jupyter Notebook under File -> Download as -> PDF - DataFrame as Image.

png

In a separate Python script, import the dataframe_image package and pass the file name of your notebook to the convert function.

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.

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

As a Python Library

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',
                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 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 which first converts your notebook to markdown using dataframe_image.

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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dataframe_image-0.0.9.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dataframe_image-0.0.9-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file dataframe_image-0.0.9.tar.gz.

File metadata

  • Download URL: dataframe_image-0.0.9.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for dataframe_image-0.0.9.tar.gz
Algorithm Hash digest
SHA256 37c6b74fbe48bad5ac6e0d781c915d8d8b2ad78e84c21ea714c948eb30913888
MD5 2be4d9f2ec4f3f6259c7c95a0b94d123
BLAKE2b-256 e7e597c1137b0fbe4f59560e62091e211c83d4f4d284c3bbb8bed37ca220c7ba

See more details on using hashes here.

File details

Details for the file dataframe_image-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: dataframe_image-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for dataframe_image-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2ef9850e65606fdab7a16d5eacaf59fd99790879ab5cc74f0613fb870631bcac
MD5 718e8aefd7a9531fd64e1f6e911aaa05
BLAKE2b-256 a88715f97590fc2e62aad08b7690270fa20c78ecb168f80b5f0c005d6bf42987

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page