【问题标题】:Ipython Notebook not printing type() in dataframeIpython Notebook 不在数据框中打印 type()
【发布时间】:2012-12-15 02:14:38
【问题描述】:

这是一个非常奇怪的错误:

以下代码:

a = 'string1'
b = 'string2'

test_dict = {'col1':{a:type(a), b:type(b)},'col2':{a:type(a), b:type(b)}}
pd.DataFrame(test_dict)

在正常的 ipython 控制台中,按预期产生以下结果:

                col1          col2
string1  <type 'str'>  <type 'str'>
string2  <type 'str'>  <type 'str'>

但是在 ipython notebook 中,应该显示类型的单元格是空的:

【问题讨论】:

    标签: python pandas ipython ipython-notebook


    【解决方案1】:

    一种解决方法是打印数据帧,这样可以更好地使用 ipython 笔记本:

    In [144]: print pd.DataFrame(test_dict)
    
                     col1          col2
    string1  <type 'str'>  <type 'str'>
    string2  <type 'str'>  <type 'str'>
    

    我发现 HTML 表格中的行让人分心,所以这个解决方法是我的默认设置。

    【讨论】:

      【解决方案2】:

      我怀疑如果您在浏览器中执行 View->Source,您将看到预期的 。发生的事情是浏览器认为这是一个 HTML 标记,没有识别它,并简单地将其丢弃。

      注意:如果我没有在这个答案中输入&amp;amp;lt;type ...&gt;,我的答案也会发生同样的事情。

      【讨论】:

      • 我能够通过转换为字符串并注册除实际数据类型之外的所有内容来解决...不漂亮但它有效而且它更紧凑然后打印整个 废话
      • 这不是 IPython 中的错误,而是 pandas 中的错误——pandas 告诉 IPython 它已经有一个 HTML repr,IPython 信任它已正确转义,但事实并非如此。以 pandas Issue 2617 的身份打开。
      猜你喜欢
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 2015-03-04
      • 2014-02-14
      相关资源
      最近更新 更多