2013-03-06 11 views
11

Ich habe vor kurzem meine Version von Pandas aktualisiert. Ich habe die neueste stabile Version installiert jetzt:qtconsole nicht pandas datenframes als html notebook_repr_html option

pd.__version__ 
Out[5]: '0.10.1' 

vor diesem Upgrade, das ist, wie Datenrahmen in dem qtconsole Shell angezeigt wurde (dies ist nicht mein Screenshot ist, sondern nur eine i auf dem Netz gefunden).

rendering pandas dataframe as html table in qtconsole

Die neueste Version von Pandas verwendet auch einen anderen Ansatz, um die Anzeigeoptionen einstellen.

Anstatt pd.set_printoptions verwenden, Pandas möchte, dass Sie die set_option configs wie folgt verwenden:

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

Nach meiner Pandas Version aktualisieren, qtconsole nicht mehr macht Datenrahmen als HTML-Tabellen.

Ein Beispiel:

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) 

Wenn ich einen Datenrahmen erstellen ...

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 

Dies ist, was ich in der qtconsole Schale sehen:

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 

Sie können prüfen, wie Ihre Anzeigekonfigurationen sind derzeit eingestellt:

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 

Was fehlt mir, um die verschönerten HTML-Tabellen in qtconsole zu rendern?

Antwort

11

Soweit ich weiß, die notebook_repr_html Option gilt nur für das eigentliche IPython Notebook und nicht die QTConsole.

Im QTConsole können Sie tun:

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

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

Ein Problem auftreten können, wenn der HTML-Code für Ihre QTConsole Puffer zu lang ist. In diesem Fall wird sich meiner Erfahrung nach nichts zeigen.

+0

Danke, Paul. Das funktioniert! – hernamesbarbara

+0

Das verwendete Frontend sollte für Pandas allerdings nicht sichtbar sein. @hernamesbarbara, hast du versucht, Pandas in einem IPython-Notebook zu verwenden, seit du dein Upgrade durchgeführt hast? –

+0

Ja habe ich. Das Web-Notizbuch funktioniert so, wie ich es mir vorstelle. Das Problem speziell in der qtconsole, aber nicht im Notebook zu beobachten, ist Teil dessen, was ich seltsam fand. Das Verhalten war sowohl in der qtconsole als auch im Notebook identisch. Ich sehe das gleiche in meiner Windows-Umgebung bei der Arbeit und meinem Mac. – hernamesbarbara