Skip to content
Advertisement

How to color dataframe based on each group?

I have a dataframe as below

JavaScript
JavaScript
JavaScript
JavaScript

I want to color the dataframe for each Variable a different color for all columns.

enter image description here

In the above figure, the selected variables should have one color, the below variable type should in another color etc.,

How can I color the dataframe in different colors for each Variable groups?

Advertisement

Answer

You can try the below function which takes matplotlib colours and maps it back based on the Variable column:

JavaScript

enter image description here

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