【发布时间】:2021-08-14 11:40:24
【问题描述】:
我有 10-11 列的熊猫数据框。我想使用 pd.to_html(index=False,border=0) 将此数据框转换为 html。但是,我想更改返回表的 CSS。 我们可以更改数据框本身的列宽,或者从 pd.to_html() 中更改返回表的格式标签
预期表格的 HTML 代码
<table>
<thead>
<th width="5%">A</th>
<th>B</th>
<th>C</th>
<th width="3%">D</th>
<th>E</th>
<th>F</th>
</thead>
<tbody>
</tbody>
</table>
目前在 pd.to_html() 之后,我得到了这张表
<table border="0" class="dataframe">
<thead>
<tr style="text-align: right;">
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
<th>F</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
如果 tr 标记将在 thead 标记之后从输出中删除,那就太好了,因为它不是必需的
【问题讨论】: