How change color of a specific columns on my Pandas dataframe?

You need to create a styled data frame and pass it to st.dataframe:

Demo

import streamlit as st
import pandas as pd
import numpy as np

# Create mock data
np.random.seed(0)

df = pd.DataFrame({
    'A': np.random.randn(3),
    'B': np.random.randn(3),
    'C': np.random.randn(3)
})

st.title('DataFrame Column Highlighting')

# Display original dataframe
st.subheader('Original DataFrame')
st.dataframe(df)

# Select column to highlight
selected_column = st.selectbox('Select a column to highlight', options=df.columns)

# Create a styled data frame
df_styled = df.style.set_properties(subset=[selected_column], **{'background-color': 'yellow'})

# Display the styled dataframe
st.subheader('Styled DataFrame')
st.dataframe(df_styled)

1 Like