在 Jupyter 笔记本中显示 .html 文件的输出

spa*_*row 6 python jupyter-notebook

我可以使用以下代码创建一个 html 文件:

with open(file_loc+'file.html', 'w') as html:
    html.write(s.set_table_attributes("border=1").render())
Run Code Online (Sandbox Code Playgroud)

如何在不创建文件的情况下在 Jupyter Notebooks 中显示输出?

如果我只是尝试在 Jupyter 中渲染它(如下所示),那么它会显示 html 代码,而不是显示我在浏览器中看到的所需输出:

from IPython.core.display import display, HTML
s.set_table_attributes("border=1").render()
Run Code Online (Sandbox Code Playgroud)

小智 9

用这个

from IPython.display import HTML

HTML(filename="profiling/z2pDecisionTreeProfiling.html")
Run Code Online (Sandbox Code Playgroud)


edu*_*ffy 7

您需要调用 IPython 的HTML函数:

 HTML(s.set_table_attributes("border=1").render())
Run Code Online (Sandbox Code Playgroud)