[Python] Color only header with pandas

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a way to give a colour to the header of a dataframe column with pandas?

    What I have now is:

    def funct(x):

    c1 = 'background-color: #add8e6'
    df1 = pd.DataFrame('', index=x.index, columns = x.columns)
    df1['Sales in pieces last 6 weeks'] = c1
    return df1


    sales_report.style.apply(funct,axis = None).to_excel(writer)

    So, in short, I have the data frame sales_report. I want the header of the column 'Sales in pieces last 6 weeks' to have a background color. Now, the whole column without the header has that background color.

    Continue reading...

Compartilhe esta Página