her*_*ara 11 ipython pandas qtconsole
我最近升级了我的熊猫版本.我现在安装了最新的稳定版本:
pd.__version__
Out[5]: '0.10.1'
Run Code Online (Sandbox Code Playgroud)
在此升级之前,这是数据框在qtconsole shell中的显示方式(这不是我的屏幕截图,而只是我在网上找到的一个).
最新版本的pandas还使用不同的方法来设置显示选项.
而不是使用pd.set_printoptions
,熊猫希望你使用这样的set_option
配置:
pd.set_option('display.notebook_repr_html', True)
Run Code Online (Sandbox Code Playgroud)
升级我的pandas版本后,qtconsole不再将数据帧呈现为html表.
一个例子:
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)
Run Code Online (Sandbox Code Playgroud)
当我创建一个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
Run Code Online (Sandbox Code Playgroud)
这是我在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
Run Code Online (Sandbox Code Playgroud)
您可以检查当前设置的显示配置的方式:
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
Run Code Online (Sandbox Code Playgroud)
为了在qtconsole中呈现美化的html表,我缺少什么?
Pau*_*l H 11
据我所知,该notebook_repr_html
选项仅适用于实际的IPython Notebook而不适用于QTConsole.
在QTConsole中,您可以:
from IPython.display import HTML
import numpy as np
import pandas
df = pandas.DataFrame(np.random.normal(size=(75,5)))
HTML(df.to_html())
Run Code Online (Sandbox Code Playgroud)
您可能遇到的一个问题是,对于QTConsole的缓冲区,HTML太长了.在那种情况下,根据我的经验,没有任何东西会出现.