简体   繁体   English

使用 pandas 更改 excel 单元的颜色

[英]Change colour of excel cell using pandas

I am using panda lib to get dataframe of the excel file.我正在使用熊猫库来获取 excel 文件的 dataframe 文件。 I want to change the background color and save it as the excel file.我想更改背景颜色并将其保存为 excel 文件。 How Can I do it?我该怎么做?

I tried using stylers but it asked me to import Jinja2.我尝试使用样式器,但它要求我导入 Jinja2。 I use eclipse IDE and company computer.我使用 eclipse IDE 和公司计算机。 How to solve it.thanks in advance如何解决它。提前谢谢

As it is explained here : You can create a function to do the highlighting:正如这里所解释的:您可以创建一个 function 来突出显示:

def highlight_cells():
    # provide your criteria for highlighting the cells here
    return ['background-color: yellow']

And then apply your highlighting function to your dataframe:然后将突出显示的 function 应用于 dataframe:

df.style.apply(highlight_cells)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM