简体   繁体   中英

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 在此输入图像描述

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM