Hi all - ran into my first Streamlit issue I haven’t been able to resolve from the forums.
Summary
Using column_config
in conjunction with a Pandas styler object doesn’t appear to work.
Steps to reproduce
According to the docs, I can pass a pandas styler object to
st.dataframe
. This works.
df = pd.DataFrame({
'cost': [25.99, 97.45, 64.32, 14.78],
'grams': [101.89, 20.924, 50.12, 40.015]
})
st.write(df)
st.dataframe(df.style.highlight_max(axis=0))
However, passing a styled df to st.dataframe
appears to negate column_config
:
st.dataframe(df.style.highlight_max(axis=0),
column_config={'cost': st.column_config.NumberColumn('Cost',format="$%.2g"),
'grams': st.column_config.NumberColumn('Grams',format="%.2f")})
Expected behavior:
The st.dataframe
returns a styled dataframe with highlighting, and column_config formatting.
Am I doing it wrong? Or is it not possible to apply column_config to a styler object? If the latter, is the answer to do all the formatting in Pandas ahead of time?
Thanks for the input!
Debug info
- Streamlit version: 1.27
- Python version: 3.11.5, with Conda