Saving pandas styler object in anyway

Viewed 3465

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)
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

Related