python - Pandas Dataframe 到 HTML 删除索引

标签 python html pandas dataframe flask

我正在使用 Pandas 数据框将 csv 数据读入 Flask 项目。我正在尝试使用 set_index 方法删除 HTML 表中的 Dataframe 索引:

overviewTable.set_index('Tower Number', inplace=True)

当我使用此方法时,塔号标题跳到所有其他标题下方的一行。

HTML 看起来像这样:

<div class="row table-responsive">
   <div class="tower-table">
       {{ overview|safe }}
   </div>
</div>

和 Python:

overview = pandas.read_csv('../overview_table.csv')
overviewTable = overview[cols]
overviewTable.set_index('Tower Number', inplace=True)

@app.route('/')
def dash():

    return render_template('dash.html', overview=overviewTable[1:167].to_html())

还有 CSS:

.tower-table {
overflow-x: hidden;
overflow-y: scroll;
width: 100%;
height: 500px;
background-color: darkgrey;
border-color: #003430;
border-radius: 5px;
}
.tower-table tr {
height: 50px;
}
.tower-table thead tr  {
height: 100px;
border-top: none;
}

是否有另一种方法可以在不影响 header 的情况下删除索引。 或者我可以在 CSS 等中做些什么来阻止标题向下移动

最佳答案

正如@ayhan 在评论中提到的,您可以使用 .to_html(index=False) 来抑制要包含在 html 表中的索引。

只是发布它,因为不是每个人都可能看到评论。

关于python - Pandas Dataframe 到 HTML 删除索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40546119/

相关文章:

javascript - jQuery UI Slide - 在动画期间移动内容

python - 缺少可选依赖项 'tables' 。在 Pandas to_hdf

python pandas 抛出解析错误

Python:Gensim Word2vec 模型类中的 "size"参数是什么

python - 使用 python 处理此文本文件的大多数 pythonic 方式

python - 如何限制员工用户在 Django 管理页面中只能看到他们的信息?

css - 将 100% 宽度的 div 与固定宽度的 div 对齐

python - 如何在不安装的情况下使用打包的Python包

javascript - jQuery 通过单击链接更改 .CSS

python - 如何对pandas数据框中的正数进行groupby连接总和