
上QQ阅读APP看书,第一时间看更新
070 将DataFrame的所有数据转换为网页代码
此案例主要演示了使用to_html()函数将DataFrame的所有数据转换为HTML网页代码。当在Jupyter Notebook中运行此案例代码之后,将把DataFrame的所有数据转换为HTML网页代码,效果分别如图070-1和图070-2所示。

图070-1

图070-2
主要代码如下。

在上面这段代码中,df.to_html(index=False)表示将df的所有数据转换为HTML网页代码,同时删除默认的行标签。如果df.to_html(),则表示将df的所有数据转换为HTML网页代码,且包含行标签。实际测试表明,在采用此方式转换之后的HTML网页代码中,每行均有换行符“\n”,该换行符“\n”在HTML的表格中是不需要的,因此需要删除,具体内容请参考MyCode\H254\myHTML.html文件。
此案例的主要源文件是MyCode\H254\H254.ipynb。