5

Question: How can you print 2 DataFrame tables together from 1 iPython Notebook row, such that both tables are displayed in the pretty table format?

The following prints just the second one, and print df.head() does not produce a pretty table.

df = pd.DataFrame(np.random.randn(6,4), index=pd.date_range('20150101', periods=6), columns=list('ABCD'))
df2 = pd.DataFrame(np.random.randn(6,4), index=pd.date_range('20150101', periods=6), columns=list('WXYZ'))


df.head()
df2.head()

enter image description here

The following does not produce the pretty table needed:

print df.head()
print df2.head()
7
  • Are you wanting the bottom answer here: stackoverflow.com/questions/28966780/… if so I'll close as duplicate Commented May 1, 2015 at 15:27
  • df.head(), df2.head() Commented May 1, 2015 at 15:27
  • or you can use print Commented May 1, 2015 at 15:28
  • @joris print df.head() doesnt produce a pretty table Commented May 1, 2015 at 15:30
  • 1
    or from IPython.display import display, and then use display(df.head()) Commented May 1, 2015 at 15:34

1 Answer 1

5

In the IPython notebook, only the result of the last line of a cell is shown, unless it is explicitly printed or displayed.

Some options:

  • Put the second df.head() in the next cell
  • Use print df to explicitly print the dataframe -> but, this gives the text representation instead of html representation
  • Use display(df) to explicitly display the dataframe, this will give the same html representation as how a dataframe is shown by default. You need the following import for this:

    from IPython.display import display
    
Sign up to request clarification or add additional context in comments.

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.