如何根据整数位置定义Pandas数据帧中特定单元格的颜色(例如。,测向仪[1,1])与df.风格?

2024-06-16 14:50:45 发布

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

有没有可能在pandas数据帧中基于整数位置定义特定单元格的颜色,例如测向仪[1,1]熊猫造型?https://pandas.pydata.org/pandas-docs/stable/style.html

像下面这样的东西会很好,但不起作用。在

def style_specific_cell(val):

    color = 'lightgreen'
    val.iloc[2, 8] = color
    return XYZ

df = df.style.applymap(style_specific_cell, subset=['Column1']

Tags: 数据httpsorgpandasdf定义style颜色
1条回答
网友
1楼 · 发布于 2024-06-16 14:50:45

^{}与样式的助手DataFrame一起使用:

def style_specific_cell(x):

    color = 'background-color: lightgreen'
    df1 = pd.DataFrame('', index=x.index, columns=x.columns)
    df1.iloc[2, 8] = color
    return df1

df.style.apply(style_specific_cell, axis=None)

pic

示例DataFrame

^{pr2}$

相关问题 更多 >