相关疑难解决方法(0)

有条件地格式化Python pandas cell

我试图根据单元格的值来着色,突出显示或改变对Python pandas DataFrame的喜爱.例如,如果每行上的单元格大于该行第一列中的单元格,则将单元格突出显示为红色(或任何其他颜色),否则保持原样.

我在这里写了一个for循环:

for index in range(0, df.shape[0]):
    for column in range(1, df.shape[1]): # from 1 not from 0 because I only need # to compare the 2nd to the last cell of each row with the 1st cell in the row 

        if df.iloc[index][column] - df_BDE_n_months_avg_std_pct.iloc[index][0] > 0:
            then "PLEASE PUT YOUR HELP HERE, I NEED A PIECE OF CODE THAT CAN HIGHLIGHT THE CELL"
        else:
            "DO NOTHING"
Run Code Online (Sandbox Code Playgroud)

到目前为止,我还没有找到办法.任何帮助都会很棒.

python conditional-formatting highlight dataframe pandas

4
推荐指数
2
解决办法
2万
查看次数