我正在尝试将 Python Pandas Data Frame
中定义的内容保存为 HTML
页面。此外,我想让这个表保存为 HTML
表能够按任何列的值进行过滤。你能提供可能的解决方案吗?最后这应该是保存为 HTML
页面的表格。我想将此代码合并到我的 Python
代码中。谢谢
最佳答案
您可以使用 pandas.DataFrame.to_html()
.
示例:
>>> import numpy as np
>>> from pandas import *
>>> df = DataFrame({'foo1' : np.random.randn(2),
'foo2' : np.random.randn(2)})
>>> df.to_html('filename.html')
这会将以下 html 保存到 filename.html
。
输出:
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>foo1</th>
<th>foo2</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>-0.223430</td>
<td>-0.904465</td>
</tr>
<tr>
<th>1</th>
<td>0.317316</td>
<td>1.321537</td>
</tr>
</tbody>
</table>
关于Python Pandas 数据框另存为 HTML 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32430009/