11

I recently upgraded my version of pandas. I have the latest stable version installed now:

pd.__version__
Out[5]: '0.10.1'

prior to this upgrade, this is how dataframes were displayed in the qtconsole shell (this isn't my screenshot but simply one i found on the web).

rendering pandas dataframe as html table in qtconsole

The latest version of pandas also uses a different approach to setting the display options.

Rather than using pd.set_printoptions, pandas wants you to use the set_option configs like this:

pd.set_option('display.notebook_repr_html', True)

After upgrading my pandas version, qtconsole no longer renders dataframes as html tables.

An example:

import numpy as np
import pandas as pd

pd.set_option('display.notebook_repr_html', True)
pd.set_option('display.expand_frame_repr', True)
pd.set_option('display.precision', 3)
pd.set_option('display.line_width', 100)
pd.set_option('display.max_rows', 50)
pd.set_option('display.max_columns', 10)
pd.set_option('display.max_colwidth', 15)

When I create a DataFrame...

f = lambda x: x*np.random.rand()
data = {"a": pd.Series(np.arange(10) ** 2 ),
        "b": pd.Series(map(f, np.ones(10))) }
df = pd.DataFrame(data)
df

This is what I see in the qtconsole shell:

Out[4]: 
    a     b
0   0  0.15
1   1  0.74
2   4  0.81
3   9  0.94
4  16  0.40
5  25  0.03
6  36  0.40
7  49  0.43
8  64  0.56
9  81  0.14

You can check how your display configs are currently set:

opts = ["max_columns", 
        "max_rows", 
        "line_width", 
        "max_colwidth", 
        "notebook_repr_html", 
        "pprint_nest_depth", 
        "expand_frame_repr" ]

for opt in opts:
    print opt, pd.get_option(opt)

Out[5]
max_columns 10
max_rows 50
line_width 100
max_colwidth 15
notebook_repr_html True
pprint_nest_depth 3
expand_frame_repr True

What am I missing in order to render the prettified html tables in qtconsole?

user207421
  • 305,947
  • 44
  • 307
  • 483
hernamesbarbara
  • 6,850
  • 3
  • 26
  • 25

1 Answers1

11

As far as I know, the notebook_repr_html option only applies to the actual IPython Notebook and not the QTConsole.

In the QTConsole, you can do:

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

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

One problem you might encounter is if the HTML is too long for your QTConsole's buffer. In that case nothing will show up, in my experience.

Paul H
  • 65,268
  • 20
  • 159
  • 136
  • The frontend in use shouldn't be visible to pandas, though. @hernamesbarbara, have you tried using pandas in an IPython notebook since you upgraded? – Thomas K Mar 07 '13 at 13:04
  • Yes I have. The web notebook works just as I'd expect it to. Observing the issue specifically in the qtconsole but not in the notebook is part of what I found strange. The behavior used to be the same in both qtconsole and notebook. I'm seeing the same thing in both my windows environment at work and my mac. – hernamesbarbara Mar 07 '13 at 16:00
  • One quick thing, @paul. Your answer definitely works, but i did need to make a small change. Instead of importing html, I'm importing HTML (uppercase). – hernamesbarbara Mar 07 '13 at 16:04
  • @hernamesbarbara thanks for catching that. sorry for the confusion -- i've edited the response. One last thought: start a fresh QTConsle, maximize it, and *then* import pandas. I seem to recall something about pandas being aware of the size of the console window. – Paul H Mar 07 '13 at 18:38
  • It would be great to have html repr as good as notebook in the qtconsole. presumably non trivial... :S @ThomasK – Andy Hayden Mar 12 '14 at 23:02
  • 1
    @AndyHayden : The HTML rendering in the Qt rich text widget is pretty limited. We could embed webkit and write a fully web based UI, but that would be a major rewrite of the Qt console. We have an idea for a web console embedded in the notebook, though, so it's not impossible. – Thomas K Mar 13 '14 at 20:16
  • 3
    I only get `Out[14]: ` but I don't see anything. Did I miss something? – nowox Apr 03 '17 at 20:12