Pandas到_mardown()突出显示行

2024-04-29 11:37:18 发布

您现在位置:Python中文网/ 问答频道 /正文

使用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中复制粘贴一个表(带有样式)

谢谢


Tags: to代码nameindffordatalabels
1条回答
网友
1楼 · 发布于 2024-04-29 11:37:18

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

相关问题 更多 >