我想从 df.shape 返回填充背景颜色

问题描述 投票:0回答:1

我想从 df.shape 填充背景颜色从第二行返回此颜色 #A9D08E。 喜欢这张图片 enter image description here

import pandas as pd

df = pd.read_excel(r'C:\Users\Beexprss\Desktop\python\ar.xlsx')

def color_cells(val):
    if val == df.shape or val >= 1:
        return 'background-color: #A9D08E'
    else:
        return ''

styled_df = df.style.applymap(color_cells)
styled_df

我输入了上面的代码,但结果是错误的。

enter image description here

python-3.x pandas dataframe styles
1个回答
0
投票
background_color = '#A9D08E'
styled_df = df.style.set_properties(**{'background-color': background_color})
© www.soinside.com 2019 - 2024. All rights reserved.