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?

3
  • 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. Commented Oct 26, 2016 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 Commented Oct 26, 2016 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. Commented Jun 30, 2020 at 21:36

1 Answer 1

6

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 try-jupyter if you don't have it installed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.