【问题标题】:Pandas to_mardown() highlight row熊猫 to_mardown() 突出显示行
【发布时间】:2020-04-27 19:36:15
【问题描述】:

使用df.to_markdown()时是否可以更改特定行的文本颜色?

我曾尝试使用df.style.apply([styles]).to_markdown(),但它不起作用,因为它将 df 转换为样式器对象。

代码:

print(labels_data.to_markdown(headers= df.columns, tablefmt="jira",  showindex=True))

df 样式代码:


def row_name(x):
    for i in x:
        if x.name=='Control':

            return ['background: yellow']
        else:
            return ''
labels_data = count_labels(labels).sort_values('% meets', ascending=False)
labels_data.style.apply(lambda x: ['background: lightgreen' 
                                  if (x.name == 'control')
                                  else '' for i in x], axis=1)

我的用例是打印降价以在 jira 中复制粘贴表格(带有样式)。

谢谢

【问题讨论】:

    标签: python pandas jira tabulate


    【解决方案1】:

    为什么不使用 html? Html 在 markdown 中是有效的内联,但在 markdown 表中没有标准的标记行的方法(无论如何,markdown 在实践中并不是很标准)。

    【讨论】:

      猜你喜欢
      • 2020-11-01
      • 2018-10-10
      • 2022-08-19
      • 2020-05-25
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 2019-03-04
      相关资源
      最近更新 更多