0

Let say I have dataframe like this:

     col1    sub col 2     col3       col4
0    A        A_1          pass        2
1    A        A_2          pass        4
2    A        A_1          fail        4
3    A        A_1          fail        5
4    A        A_1          pass        3
5    A        A_2          fail        2

I want to change the color of the header "sub col 2" to yellow, then save it as an excel file and have an output excel file like this one when I open the file?

Output

1

1 Answer 1

3

(Assuming you are using styleframe since the question is tagged with )

You can use the apply_headers_style method with the cols_to_style argument:

from styleframe import StyleFrame, Styler

...
sf.apply_headers_style(Styler(bg_color='yellow'),
                       cols_to_style='sub col 2')
sf.to_excel('output.xlsx').save()

enter image description here

If you want the filters as well you can pass row_to_add_filters=0 to to_excel:

sf.to_excel('output.xlsx', row_to_add_filters=0).save()

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Just to add a little clarity, sf in the answer is a StyleFrame object. You can initialize a StyleFrame object with an existing dataframe, among other options. For example, sf = StyleFrame(df)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.