TableView formatting🪄

I would like to use this topic to share some formatting ideas for the TableView.

I will start with freezing the header row of the table:

s1 = df.style
header_style = {
    "selector": "th",
    "props": [
        ("text-align", "right"),
        ("background-color", "rgba(245, 245, 252)"),
        ("position", "sticky"),
        ("top", 0),
    ],
}
s1.set_table_styles([header_style])

table_result = TableResult(
    dataframe=df,
    style=s1
    )

This results in:
table_freeze_header

Please share your table view formatting ideas below.

4 Likes

Nice snippet!

To add to this: to format individual cells you can use the same snippet but with "selector": "td".

Also I use the set_properties function a lot; it works like this:

style = df.style.set_properties(**{"font-size": "14px", "text-align": "right"})

Also I love the .set_sticky function:

df.style.set_sticky(axis="index")

1 Like