Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force print dataframe in html in ipython

Here's my code

df1 = pd.DataFrame(np.arange(6).reshape(3,2),
   ....:                 columns=['A','B'])
df2 = pd.DataFrame(np.arange(6).reshape(3,2),
   ....:                 columns=['C','D'])
print df1
print '--Something Here---'
df2

here, I would get both df1 and df2 to print but only df2 that created HTML look. How can I force python to create df1 to print to html in output as well as df2 enter image description here

like image 926
JPC Avatar asked Feb 24 '26 10:02

JPC


1 Answers

I'm not sure I totally understand the point of this. Why for example would you jsut not display the output in two different cells. In general in order to force the HMTL display of data in the notebook (if for example the dataframe is too large) then you do the following

from IPython.core.display import HTML
HMTL(df.to_html())

Does this answer you quetion?

In cell 1 I would have

HMTL(df.to_html())

In cell 2 I would have

print 'something'
HTML(df2.to_html())
like image 86
Woody Pride Avatar answered Feb 27 '26 01:02

Woody Pride



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!