Skip to content

Instantly share code, notes, and snippets.

@d1manson
d1manson / images_in_pandas.md
Last active April 19, 2018 23:10
show images when displaying 2d arrays in iPython and Pandas

As of writing, this is only possible with my fork of pandas, but hopefully it will make its way into the main pandas stable branch.

The purpose of the fork is to let you specify a custom html formatter for individual columns in a data frame.


In this example we create a formatting function which takes a numpy array and returns a string of the form <img src='--base64-encoded-data'/>. This means that the numpy array is displayed as an image.

Below is the code we use to define our custom format function. Note that the function takes a single element from the data frame and returns and html string::

#!/usr/bin/python3
from sys import exit
from sys import stdout
from sys import path as syspath
from os import path as osp
from os import stat, makedirs
import argparse
from shutil import copyfile