如何根据非空列突出显示所有行-pandas

发布于 2025-02-09 06:09:40 字数 364 浏览 1 评论 0原文

我有一个由大量数据组成的数据框。我要做的是在称为“类型”的列中查看所有值,如果它不是空的,请突出显示整个行。

这就是我现在要重点介绍的目前

def highlight_row(rows):
    if not rows is None:
        return ['background-color: blue'] * len(rows.values)

df.style.apply(highlight_row, axis=1)

正在尝试将其引入的,以在数据框架df中突出显示,我将导出到CSV文件中以在Excel中查看。

I have a DataFrame that consists of a large sum of data. What I'm trying to do is to look through all values in a column called 'Type' and if it's not empty, highlight that entire row.

This is what I have right now for the highlighting

def highlight_row(rows):
    if not rows is None:
        return ['background-color: blue'] * len(rows.values)

df.style.apply(highlight_row, axis=1)

I'm trying to get this to highlight it in the data frame df that I'm exporting to a CSV file to view in excel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文