gpt4 book ai didi

html - 使用 pandas dataframe.to_html() 时重新格式化列宽

转载 作者:太空宇宙 更新时间:2023-11-04 16:16:48 25 4
gpt4 key购买 nike

我有一个 pandas 数据框,我想在 html 模板中显示为表格。它在大多数情况下都有效,但数据框中的一些字符串被截断了。我正在使用 to_html() 将我的 pandas 数据框转换为 html 友好表并尝试使用 col_space 参数,但它似乎没有任何影响。

python代码:

options = dbi.getDBTables()  #returns a list of the names of available tables

table_headers = []

for table_name in options:
table_name = str(table_name)
df = dbi.selectDF("SELECT * FROM %s LIMIT 1" % table_name) #gets the actual dataframe for each table name
header = df.columns.values
header = "<br>".join(header)
table_headers.append(header)

header_dict = dict(zip(options,table_headers))
table_options = pandas.DataFrame(header_dict,index=[0])
table_options = table_options.to_html(classes=["table table-hover"],index=False,escape=False,col_space=400) #changing the col_space does nothing.
search_dict = {'table_names':table_options}

html代码:

<div class="table-responsive">
{{ table_names | safe }}
</div>

发生截断的表图片: enter image description here

如何让 pandas 停止截断(在图片中显示为“...”)内容?

非常感谢!

最佳答案

只需要设置pandas.set_option('display.max_colwidth',100)

关于html - 使用 pandas dataframe.to_html() 时重新格式化列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31550889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com