我想将带有Pandas的DF导出到HTML格式的表中,但我不想使用Pandas对其表所做的任何默认样式,我更希望只使用骨存储表。在使用to_html函数时,是否有一种简单的方法可以做到这一点?
因为它只是一行代码,所以实际上没有一个最小的可重复示例,我只想要html_file = df.to_html()
使我的HTML文件表从
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
至
<table>
<thead>
<tr>
发布于 2022-04-24 22:45:32
对于我来说,在生成html
之后删除属性
df = pd.DataFrame(
{
"a": [1]
})
from bs4 import BeautifulSoup
soup = BeautifulSoup(df.to_html(), features="lxml")
for tag in soup.find_all(True):
tag.attrs.clear()
print(soup.prettify())
<html>
<body>
<table>
<thead>
<tr>
<th>
</th>
<th>
a
</th>
</tr>
</thead>
<tbody>
<tr>
<th>
0
</th>
<td>
1
</td>
</tr>
</tbody>
</table>
</body>
</html>
https://stackoverflow.com/questions/71995105
复制