Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style Pandas Columns Separately

I want to apply separate background gradient to different columns in my pandas dataframe

a b c
-----
1 2 3
4 5 6
9 2 3

I want one background gradient for column a and a different background gradient to another column as such.
How do I do that?
Thank you very much.

like image 413
imdevskp Avatar asked Mar 02 '23 19:03

imdevskp


1 Answers

You can apply background_gradient to each individual column and compose multiple styles in a single call:

df.style\
    .background_gradient(cmap="cool", subset=['a'])\
    .background_gradient(cmap="bone", subset=['b'])\
    .background_gradient(cmap="winter", subset=['c'])

enter image description here

like image 141
foglerit Avatar answered Mar 16 '23 10:03

foglerit