如何删除“dataframe”类df.to\u html?

2024-09-27 21:30:06 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我有

df.to_html('table.html', classes='tablecss')

它将输出一个表:

<table border="1" class="dataframe tablecss">

如何使它只显示“tablecss”而不显示“dataframe tablecss”?你知道吗


Tags: todataframedfhtmltableclassclassesborder
1条回答
网友
1楼 · 发布于 2024-09-27 21:30:06

最简单的解决方案(也许有更干净的解决方案):

import re
html_updated = re.sub("class=\"dataframe ", "class=\"", df.head(5).to_html(classes='tablecss'))
with open("table.html", "w") as ouput_file:
    ouput_file.write(html_updated)

相关问题 更多 >

    热门问题