Python in VSCode: Why can come cell outputs be set to HTML, while others only text?

Viewed 766

I am using Jupyter notebooks and Python in VSCode. In the recent update (I don't know the version numbers), they put in the functionality to change the output style. However, some cell output allow me to set it to HTML, while others only text. Why would this be? And it can't be the contents/code - for example, I have one cell which gives nice HTML output for a describe method: enter image description here

While, further down, I have the same, but then I get enter image description here

any ideas? Also any idea as to why the two instances of the same method is not giving the same results?

2 Answers

It looks like your 2nd cell doesn't call the function describe, it simply accesses it.

However, if you ever run into an issue with displaying, for instance, pandas as raw text instead of an HTML table, you probably want to look into IPython's display module.

You can import it like so:

from IPython.display import display

display is actually run under-the-hood on your last line of code. This is why writing:

df

will show you a pd.DataFrame as a table, whereas that won't happen in a program or regular Python console.


There are also a host of other tools in IPython.display, like Markdown, HTML, and Image, to name a few.

That's because describe() and describe are different. Use function type(), you can see describe() is pandas.core.series.Series, while describe is method:

enter image description here

So the data they show is different too.

Related