2

I've searched across stackoverflow and a number of other sites and Im not quite finding the answer to my problem. In short, when I run Python from either the interactive command line or from a source file in Canopy, and that code involves attempting to display a panda dataframe or even manual markup as html, it does not work. I simply get the following output:

<IPython.core.display.HTML object>

I have checked preferences and have looked for other possible sources of error. I have tried different combinations of imports and diplay methods as below. They all return the same thing above, never the actual HTML.

#from IPython.display import HTML
#from IPython.core.display import display
#display_html(av.head(10).to_html())

from IPython.display import display, HTML
display(HTML('<h1>Hello World</h1>'))

Note that av is just a dataframe.

Any help would be appreciated. I feel like there is a ridiculously simple fix I am missing.

  • Are you asking how to get the raw markup to display, or how to actually render it? You can only render HTML in a browser, so there's no way a plaintext environment like a regular Python console is going to actually show you the rendered HTML. – BrenBarn Jun 24 '16 at 06:10
  • Ah, ok, I was of the understanding that IPython could render HTML inline on the console. Regardless though, it wouldn't even spit out the raw HTML anywhere that I could find. – Steven Schiavoni Jun 25 '16 at 21:03
  • It looks like you can get the raw HTML from the `.data` attribute of the HTML object, e.g., `HTML('

    Hello World

    ').data`. For a DataFrame, just using `to_html()` by itself (without using any of the IPython display stuff) will give you the HTML representation.
    – BrenBarn Jun 25 '16 at 22:57
  • Thanks! At the very least the .data attribute should be useful. I believe I already tried to_html() with no luck though. – Steven Schiavoni Jun 28 '16 at 03:12
  • Are you saying `print(av.head().to_html())` doesn't show you HTML source? – BrenBarn Jun 28 '16 at 03:42
  • It actually worked this time! Spat out the raw HTML to the console. I'm new to Python but I assume I could also just write it to a file and voila I'd be good to go. Thanks for the help! – Steven Schiavoni Jun 30 '16 at 03:40
  • It might be this issue http://stackoverflow.com/questions/37041696/html-not-rendering-properly-with-canopy-1-7-1-3323-ipython-4-1-2 – Keith Aug 18 '16 at 00:32

0 Answers0