dataframe-image

0.2.7 · active · verified Thu Apr 16

dataframe-image is a Python library that enables embedding pandas DataFrames as images in PDF and Markdown files when converting from Jupyter Notebooks. It ensures DataFrames, including any applied styling, appear exactly as they do in a Jupyter Notebook, rather than as raw text or simple LaTeX tables. The library also provides functionality to export individual DataFrames as image files from Python scripts. It is actively maintained, with version 0.2.7 being the current release.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a styled pandas DataFrame and export it as a PNG image using `dataframe_image.export`. The `dfi.export` function captures the DataFrame's appearance, including styling, and saves it to the specified file.

import pandas as pd
import numpy as np
import dataframe_image as dfi

# Create a sample DataFrame
df = pd.DataFrame(np.random.randn(6, 4), columns=list('ABCD'))

# Apply some styling
df_styled = df.style.background_gradient(cmap='Blues').set_caption('My Styled DataFrame')

# Export the styled DataFrame as a PNG image
dfi.export(df_styled, 'styled_dataframe.png')

print("Styled DataFrame exported to styled_dataframe.png")

view raw JSON →