5
votes

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?

1
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
added following and it works: f = open(path+filename,'w'); f.write(df.style.background_gradient().render()); f.close().... Thanks so much - racket99
@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

1 Answers

4
votes

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.