4

I understand from here: How can I change the styles of pandas DataFrame headers?, that pandas column row is set by the set_table_styles method. I do not know the HTML code for the table styles. Can someone please help me simply add a background color black, and white text?

df2.style.set_table_styles(
   [{'selector': 'th',
   'props': [('background-color', 'black'),('font color', '#FFFFFF')]}])

this does not show the font color. Is there somewhere I can find a list of these properties?

1 Answer 1

9

This is Cascading Style Sheets (CSS)

Links

  1. https://www.w3schools.com/cssref/
  2. https://cssreference.io/
  3. https://developer.mozilla.org/en-US/docs/Web/CSS/Reference

You want 'color' not 'font color' (IIUC)

    df = pd.DataFrame(1, [*'abc'], [*'xyz'])

    df.style.set_table_styles(
       [{
           'selector': 'th',
           'props': [
               ('background-color', 'black'),
               ('color', 'cyan')]
       }])

enter image description here

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

3 Comments

Thanks pi. I found the 'color' shortly after asked. Thanks for the external references.
Hey, this is great. How would you make edits for only one column instead of all columns simultaneously?
@dayxx369 Were you able to figure this out? I would like to know how to split a particular cell into 2 columns. Something like this stackoverflow.com/questions/19115560/…

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.