1

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:

                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:

enter image description here

2 Answers 2

4

I suspect that if you do a View->Source in your browser you will see the expected <type ...>. What's happening is that the browser thought this was an HTML tag, didn't recognize it, and simply threw it out.

Note: if I had not typed &amp;lt;type ...> in this answer, the same thing would have happened to my answer.

Sign up to request clarification or add additional context in comments.

2 Comments

I was able to solve by converting to a string and reg ex'ing everything but the actual data type out...not pretty but it works and it's more compact then printing the whole <type 'str'> nonsense
This is not a bug in IPython, it is a bug in pandas - pandas is telling IPython that it already has an HTML repr, which IPython trusts is properly escaped, but it is not. Opened as pandas Issue 2617.
3

A workaround is to print the dataframe, which makes it play better with the ipython notebook:

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.