1

I was wondering if there is a good way to format the column titles in pandas as well as certain column values in order to higlight values in a column.I will eventually be exporting to excel, but it would be nice if I could do the formatting before that step. Here's a simple example dataframe. Let me know if there are any good packages and tips to using them would be appreciated.

Say I wanted to highlight any cells in column 2 that are negative. Also, if there is a way to fill the white space behind the column titles and make them bold that would be great.

COL1  COL2  COL3
0     a    -2
1     a     4
2     b     10
3     b     -8
4     a     10
5     b     5
0

1 Answer 1

1

Try something like this.

def highlight(value):
    if value < 0:
        return ['background-color: yellow']

df.style.applymap(highlight)

You'll get more examples here for reference - https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html.

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

Comments

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.