qtconsole不会将熊猫数据框呈现为html notebook_repr_html选项
发布时间:2020-12-14 19:00:31 所属栏目:资源 来源:网络整理
导读:我最近升级了我的版本的大熊猫.我现在安装了最新的稳定版本: pd.__version__Out[5]: '0.10.1' 在升级之前,这是数据框在qtconsole shell中的显示方式(这不是我的屏幕截图,只是我在网络上找到的一个). 最新版本的大熊猫也使用不同的方法设置显示选项. 而不是
我最近升级了我的版本的大熊猫.我现在安装了最新的稳定版本:
pd.__version__ Out[5]: '0.10.1' 在升级之前,这是数据框在qtconsole shell中的显示方式(这不是我的屏幕截图,只是我在网络上找到的一个). 最新版本的大熊猫也使用不同的方法设置显示选项. 而不是使用pd.set_printoptions,大熊猫希望您使用set_option配置,如下所示: pd.set_option('display.notebook_repr_html',True) 升级我的熊猫版本后,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) 当我创建一个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中看到的: 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 您可以检查当前设置显示配置的方式: 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 为了在qtconsole中渲染漂亮的html表,我缺少什么? 解决方法
据我所知,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()) 您可能会遇到的一个问题是,如果您的QTConsole缓冲区的HTML太长.在这种情况下,根据我的经验,没有什么会出现. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |