Skip to content
Advertisement

Pandas style: How to highlight diagonal elements

I was wondering how to highlight diagonal elements of pandas dataframe using df.style method.

I found this official link where they discuss how to highlight maximum value, but I am having difficulty creating function to highlight the diagonal elements.

Here is an example:

JavaScript

This gives following output: enter image description here

I am wanting a yellow highlight across the diagonal elements 1,3,7,11 only.

How to do that?

Advertisement

Answer

The other answer is pretty good but I already wrote this so….

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement