【发布时间】:2021-09-09 11:37:40
【问题描述】:
我基本上想要一个具有右对齐表格单元格条目和最小列宽 100 的表格。我有两种方法可以在 HTML 中显示 Pandas 数据框df:
html = df.style.applymap(color_negative_red).set_precision(5).set_table_attributes(
'class = "dataframe table-bordered table-striped table-hover').set_properties(
**{'width': '10em', 'text-align': 'right'}).render()
display(HTML(html)
在这种方法中,我不知道如何使用 Styler 对象隐藏行索引(即,在渲染之前我无法设置 index = False 参数。
和:
return df.to_html(index=ind, justify = {"right"}, col_space = 100,
classes = ["table-bordered", "table-striped", "table-hover"])
此方法使用to_html,似乎不适用于justify 和col_space 参数。
我该如何做/找到解决这两个问题的方法?
【问题讨论】:
标签: python pandas dataframe pandas-styles