简体   繁体   English

如何在ipython中强制打印html中的数据帧

[英]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. 在这里,我会得到df1和df2打印,但只有df2创建HTML外观。 How can I force python to create df1 to print to html in output as well as df2 如何强制python创建df1以在输出和df2中打印到html 在此输入图像描述

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 一般来说,为了强制HMTL在笔记本中显示数据(例如数据帧太大),那么你可以执行以下操作

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

Does this answer you quetion? 这回答你的问题吗?

In cell 1 I would have 在单元格1中我会有

HMTL(df.to_html())

In cell 2 I would have 在单元格2中我会有

print 'something'
HTML(df2.to_html())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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