Problem Solved: Custom Pandas styling not rendering when reopening notebook

Quick fix for Pandas styling not showing up when reopening Jupyter notebooks - use jupyter trust command to enable custom styling rendering.
ml
jupyter
pandas
Author

Greg Gandenberger

Published

August 5, 2021

Pandas has a variety of methods for styling notebooks. I have been using those methods in the model_inspector library to display correlation matrices and confusion matrices in Jupyter notebooks with appropriate highlighting.

A correlation matrix rendered with appropriate coloring using Pandas styling methods in the model_inspector library. Note that it uses a diverging colormap so that positive values are red and negative values are blue. I often see sequential colormaps used here, which make it hard to distinguish between positive, negative, and near-zero values.

I recently encountered a problem with this approach: DataFrames were not rendering with custom styling when I reopened a notebook after saving it. After an hour or two of fruitless Googling, I figured out why: the notebook was not trusted, so Jupyter was not running the code to do the custom rendering when I reopened it. Running the Terminal command jupyter trust my_notebook.ipynb fixed the problem.