Pandas Dataframe到HTML的删除索引 [英] Pandas Dataframe to HTML remove index
问题描述
我正在使用熊猫数据框将csv数据读取到Flask项目中.我正在尝试使用set_index方法删除HTML表中的Dataframe索引:
I'm using a panda dataframe to read csv data into a Flask project. I'm trying to remove the Dataframe indexes in the HTML table using the set_index method:
overviewTable.set_index('Tower Number', inplace=True)
当我使用此方法时,塔号标题会在所有其他标题下方跳下一行.
When I use this Method the Tower Number Header jumps down a row below all the other headers.
HTML看起来像这样:
The HTML looks like this:
<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;
}
还有另一种方法可以删除索引而不影响标题. 还是我可以在CSS等中做些什么来阻止标头向下移动
Is there another method to remove the indexes without affecting the headers. Or is there anything I could do in the CSS etc to stop the header moving down a row
推荐答案
正如@ayhan在评论中提到的那样,您可以使用.to_html(index=False)
压住要包含在html表中的索引.
As mentioned by @ayhan in the comments you can use .to_html(index=False)
to surpress the index to be included in the html table.
之所以发布它,是因为并非所有人都能看到评论.
Just posted it because not everyone might see the comment.
这篇关于Pandas Dataframe到HTML的删除索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!