This project has moved and is read-only. For the latest updates, please go here.

pandas DataFrame HTML display in the Interactive Window (IPython)

Oct 2, 2013 at 3:49 PM
If I start an independent Qt Console and run the following code:

from IPython.display import HTML
import numpy as np
import pandas

df = pandas.DataFrame(np.random.normal(size=(75,5)))

I get a nicely formatted HTML table. However, if I run the same code on a newly started Interactive Window running IPython (either with or without PyLab) I get the message:

<IPython.core.display.HTML at 0x1a6a28d0>

and no table on the screen.

Do I need to change something in my configuration?

This is the Python version (from WinPython, including IPython 1.0):
'3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)]'

and the pandas version is '0.12.0'

Thanks for any suggestions.
Oct 2, 2013 at 4:33 PM
Unfortunately, we don't have any support for rendering HTML in the Interactive Window. Your best option right now would be to write the HTML to a file and open it in the internal browser.

For example:
with open(r'C:\Users\Me\Documents\table.html', 'w') as f:
And then open the internal web browser through View->Other Windows-Web Browser (maybe Ctrl+Alt+R, depending on your settings) and put the path into the URL bar. Then you can hit refresh (not F5 - it looks like the web browser refresh only has a toolbar button and no shortcut, at least on VS 2012) whenever you update the file.

Long term, we'll probably add a variable explorer (vote for the feature here) that can view the DataFrame directly.
Oct 2, 2013 at 5:39 PM
That is helpful. However, I remember having displayed pandas DataFrames nicely formatted in the Interactive Window a few weeks ago, with frames around each cell. Maybe there is another way of doing it, without using HTML. I just don't remember the exact steps I followed.
Oct 2, 2013 at 5:42 PM
Looking at the docs for DataFrame, were you using df.to_string()?
Oct 2, 2013 at 6:50 PM
I don't remember. I just tried df.to_string() and it prints a long string to the screen, unformatted. Carriage returns ('\n') do not break lines.

I tried the HTML code in Spyder/IPython and it works fine. I thought PTVS was just passing on commands to standard IPython.
Oct 2, 2013 at 7:38 PM
We are, but we're not using the standard front-end, which is why this will be behaving differently. All of the relevant code is in if you want to make changes (and submit patches) - the write_data function is a good starting point, since we already handle images here. While you won't be able to extend our rendering (without modifying the C# code), you should be able to add special conversions to plain text.

Also, print(df.to_string()) will display the string with proper line breaks. We display the repr() by default, which shows control characters as escapes rather than doing what they mean.
Oct 2, 2013 at 7:42 PM
print(df.to_string()) is quite good. Thanks!