【问题标题】:How to add border in pandas dataframe to html table row header?如何将 pandas 数据框中的边框添加到 html 表格行标题?
【发布时间】:2019-09-14 06:02:16
【问题描述】:

Pandas 样式选项让我格式化数据,但我想为列标题添加边框,即第 0 行。

htmlFooterOutdatedList = dfServerOutdated[['System Name','IP Address','Last Communication','DAT (VSE)','OS Type','Status']].style.hide_index().set_properties(**{'font-size': '10pt','background-color': '#edeeef','border-color': 'black','border-style' :'solid' ,'border-width': '1px','border-collapse':'collapse', 'padding': '5px'}).applymap(datversion,subset = 'DAT (VSE)').applymap(LTSCDate,subset = 'Last Communication').background_gradient(cmap='PuBu', low=0, high=0, axis=0, subset='DAT (VSE)', text_color_threshold=0.458).set_table_styles([{'selector': 'th', 'props': [('font-size', '12pt')]}]).set_properties(subset=['Last Communication'], **{'width': '180px'}).set_properties(subset=['System Name'], **{'width': '30px'}).set_properties(subset=['Status'], **{'width': '90px'}).render()

我可以为列标题添加边框吗?

【问题讨论】:

    标签: python html python-3.x pandas


    【解决方案1】:

    在您的(诚然很长的)代码行中,您已经拥有:

    .set_table_styles([{'selector': 'th', 'props': [('font-size', '12pt')]}])
    

    您可以通过常见的 CSS 属性进行扩展,例如:

    .set_table_styles([{'selector': 'th', 'props': [('font-size', '12pt'),('border-style','solid'),('border-width','1px')]}])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-19
      • 2012-04-19
      • 2017-05-02
      • 1970-01-01
      • 2020-10-17
      • 2013-03-06
      • 2020-06-18
      • 2020-01-28
      相关资源
      最近更新 更多