Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving pandas styler object in anyway

Here's a styler object with a background gradient:

enter image description here

I'm just looking for anyway to save it as is. Have tried using .render() but not sure what to do with that HTML code, and from reading other questions on the subject it seems there is no current way to save these. Is there a hackish way to do it?

Here is the array:

array([[ 0.264     ,  0.271     ,  0.285     ,  0.289     ,  0.329     ],
   [ 0.053     ,  0.051     ,  0.045     ,  0.038     ,  0.031     ],
   [ 0.006     ,  0.007     ,  0.009     ,  0.01      ,  0.01      ],
   [-3.98650106, -3.95728537, -3.99767582, -4.20624136, -3.54186842],
   [-3.22600677, -2.87623307, -2.03420988, -1.54443176, -1.41006671]])

and the line of code I have:

df.style.background_gradient(cmap='RdYlGn',low=.09,high=.18,axis=1)
like image 809
thomas.mac Avatar asked Oct 28 '25 12:10

thomas.mac


1 Answers

Starting from Pandas 0.20.0 you can easily save it to Excel file:

 df.style.background_gradient(cmap='RdYlGn',low=.09,high=.18,axis=1) \
   .to_excel('d:/temp/a.xlsx', engine='openpyxl')

Result:

enter image description here

like image 185
MaxU - stop WAR against UA Avatar answered Oct 30 '25 01:10

MaxU - stop WAR against UA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!