有没有人有将 pandas 数据透视表发布到 html 页面的经验? 将列表发布为表格很简单,但我不知道 pandas pivot 的语法。 现在在公共(public)汽车上,所以我上车时会发布一些代码
谢谢
最佳答案
数据透视表就是一个 DataFrame,因此它具有文档中描述的 to_html()
方法 here
它将输出表格的 html 代码,例如,使用这个非常简单的数据框:
In [1]: df
Out[1]:
A B
0 0 1
1 2 3
In [2]: print df.to_html()
Out[2]:
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>0</td>
<td>1</td>
</tr>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
关于python - 通过 html 发布 pandas 数据透视表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31424202/