如何使用df.to_html删除“数据框”类?

时间:2018-10-26 15:43:04

标签: python pandas

假设我有

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

它将输出一个表:

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

如何使其仅显示“ tablecss”而不显示“ dataframe tablecss”?

1 个答案:

答案 0 :(得分:0)

最简单的解决方法(也许有更清洁的解决方案):

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)