2
data = {
    'X': [3, 2, 0, 1], 
    'Y': [0, 3, 7, 2]
}

df = pd.DataFrame(data, index=['A', 'B', 'C', 'D'])
df.style.set_properties(**{
    'font-family':'Courier New'
})
df

The index column is displayed in bold, is it possible to change font of index column?

1 Answer 1

2

You must use table_styles. In this example I manage to make the "font-weight":"normal" for the index and columns:

Let's define some test data:

import pandas as pd
df = pd.DataFrame({'A':[1,2,3,4],
                   'B':[5,4,3,1]})

We define style customization to use:

styles = [
    dict(selector="th", props=[("font-weight","normal"),
                               ("text-align", "center")])]

We pass the style variable as the argument for set_table_styles():

html = (df.style.set_table_styles(styles))
html

And the output is: enter image description here

Please feel free to read about the documentation in pandas Styling for more details.

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.