【问题标题】:How to adjust row height with pandas Styler如何使用 pandas Styler 调整行高
【发布时间】:2022-01-26 02:38:31
【问题描述】:

我有一个样式化的 pandas DataFrame,我想将其导出为 HTML,其行数比默认值小。我对 CSS 了解不多,所以到目前为止我还没有找到让它工作的方法。可以实现吗?如果可以,如何实现?

import pandas as pd

df = pd.DataFrame({"foo": [1, 2, 3], "bar": [4, 5, 6]})
styler = df.style
...  # Here I adjust a few styling options
html = styler.to_html()

【问题讨论】:

  • 较小的行是什么意思?
  • 我的意思是高度较小的行!

标签: python html css pandas


【解决方案1】:

设置行和数据单元格行高的样式并重置填充

styler.set_table_styles([
    {"selector": "tr", "props": "line-height: 12px;"},
    {"selector": "td,th", "props": "line-height: inherit; padding: 0;"}
])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    • 2021-04-26
    • 2021-05-14
    • 2021-02-12
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    相关资源
    最近更新 更多