Skip to content
Advertisement

Pandas Styler Subset column by values

I’m using the following to color the cells in a dataframe:

JavaScript

This successfully applies the background gradient to the values in col1

However, I’d like to something like the following:

JavaScript

Which does not work

The idea is to only apply the gradient to values in col1 which are less than x, and display the full dataframe where col1 >= x is un-colored.

Seems like there should be an easy way to do this but I can’t seem to get the argument into the right format for subset.

Thanks in advance for the help!

Advertisement

Answer

You need to use pd.IndexSlice:

JavaScript

Output:

enter image description here

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