[英]Ipython Notebook not printing type() in dataframe
This is a pretty bizarre bug: 这是一个非常奇怪的错误:
The following code: 如下代码:
a = 'string1'
b = 'string2'
test_dict = {'col1':{a:type(a), b:type(b)},'col2':{a:type(a), b:type(b)}}
pd.DataFrame(test_dict)
In a normal ipython console yields the following as expected: 在正常的ipython控制台中,按预期产生以下结果:
col1 col2
string1 <type 'str'> <type 'str'>
string2 <type 'str'> <type 'str'>
However in the ipython notebook, the cells where the type should be displayed is empty: 但是在ipython笔记本中,应显示类型的单元格为空:
I suspect that if you do a View->Source in your browser you will see the expected <type ...>. 我怀疑如果在浏览器中执行View-> Source,您将看到预期的<type ...>。 What's happening is that the browser thought this was an HTML tag, didn't recognize it, and simply threw it out.
发生的情况是浏览器认为这是HTML标记,无法识别它,只是将其丢弃。
Note: if I had not typed &lt;type ...>
in this answer, the same thing would have happened to my answer. 注意:如果我没有在此答案中键入
&lt;type ...>
,则我的答案将发生相同的事情。
A workaround is to print the dataframe, which makes it play better with the ipython notebook: 一种解决方法是打印数据框,从而使其在ipython笔记本上更好地发挥作用:
In [144]: print pd.DataFrame(test_dict)
col1 col2
string1 <type 'str'> <type 'str'>
string2 <type 'str'> <type 'str'>
I find the lines in the HTML tables distracting, so this workaround is my default. 我发现HTML表中的行分散了注意力,因此此替代方法是我的默认设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.