Home > database >  How to colorize all rows of a dataframe based on values of a column dynamically?
How to colorize all rows of a dataframe based on values of a column dynamically?

Time:09-21

Let's say I have a dataframe like the following;

df = pd.DataFrame({'Sample': ['A', 'B', 'C', 'D','E','F'],
                    'NFW': [8.16, 8.63, 9.25, 8.97, 7.5, 8.21],
                    'Qubit': [55, 100, 229, 30, 42, 33],
                    'Lane': ['1', '1', '2', '2', '3', '3']})

I want to colorize the background of all rows based on the values of the Lane column dynamically. Also, I'll write this dataframe to an excel file and I need to keep all style changes in there too.

CodePudding user response:

IIUC, you can use a colormap (for example from enter image description here

  • Related