Styling a row in a dataframe

I’m trying to render a dataframe in my app and highlight a particular row.

There’s a stackoverflow answer for this https://stackoverflow.com/questions/50100635/highlight-color-a-panda-data-frame-row-by-index

but this involves calling the apply method, which as far as I understand it actually does the rendering, when what I want is to modify the Styler object so I can pass it to streamlit as shown here

How do i do that?

Hi @amn41,

Welcome to the forum :wave:

The second example in the dataframe docs that you referenced shows how to style cells.

You can also pass a Pandas Styler object to change the style of the rendered DataFrame:

>>> df = pd.DataFrame(
...    np.random.randn(10, 20),
...    columns=('col %d' % i for i in range(20)))
...
>>> st.dataframe(df.style.highlight_max(axis=0))

Here are some additional examples


1 Like