7

This may be a very dumb question, but I cannot seem to see the output of the Pandas Styler. I use the following simple example posted previously by another user.

df = pd.DataFrame([[3,2,10,4],[20,1,3,2],[5,4,6,1]])
df.style.background_gradient()

I understand the output of df.style creates a Styler object but how can I actually visualize this?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
racket99
  • 635
  • 8
  • 17
  • 2
    You must be using a jupyter notebook which automatically renders the Styler objects. Else, you need to specifically call the `render()` function, like `df.style.background_gradient().render()` and do file open/write/close and go to that html file and view the rendering. It's a rather cumbersome process. So, try and use ipython notebooks for such purposes. – Nickil Maveli Oct 26 '16 at 17:47
  • 2
    added following and it works: f = open(path+filename,'w'); f.write(df.style.background_gradient().render()); f.close().... Thanks so much – racket99 Oct 26 '16 at 18:09
  • @racket99 I am having a similar problem and couldnt figure out a way to print in pycharm using styler. I wasnt able to figure out using files option that you shared. Would you be able to share a snippet. – ashwin3086 Jun 30 '20 at 21:36

1 Answers1

5

The dataframe styling will only be rendered in Jupyter notebooks. Your code, for instance, looks like this:

Rendered dataframe in a notebook

You can experiment with notebooks on tmpnb.org if you don't have it installed.

chthonicdaemon
  • 19,180
  • 2
  • 52
  • 66