问题描述
我最近升级了我的熊猫版本。我现在安装了最新的稳定版本:
I recently upgraded my version of pandas. I have the latest stable version installed now:
pd.__version__
Out[5]: '0.10.1'
在此次升级之前,这是数据框在qtconsole shell中的显示方式(这不是我的截图,但只是我在网上找到的一个。)
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).
最新版本的pandas也使用不同的方法来设置显示选项。
The latest version of pandas also uses a different approach to setting the display options.
pandas希望你使用 set_option 而不是
pd.set_printoptions
code>这样的配置:
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)
升级我的pandas版本后,qtconsole不再将数据帧呈现为html表。
After upgrading my pandas version, qtconsole no longer renders dataframes as html tables.
一个例子:
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)
我创建了一个DataFrame ...
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
这就是我在qtconsole中看到的shell:
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
为了呈现美化的html,我缺少什么qtconsole中的表?
What am I missing in order to render the prettified html tables in qtconsole?
推荐答案
据我所知, notebook_repr_html
选项仅适用于实际的IPython笔记本而不适用于QTConsole。
As far as I know, the notebook_repr_html
option only applies to the actual IPython Notebook and not the QTConsole.
在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())
您可能遇到的一个问题是HTML太长了QTConsole的缓冲区。在这种情况下,根据我的经验,没有任何东西会出现。
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.
这篇关于qtconsole没有将pandas数据帧渲染为html notebook_repr_html选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!