Dataframe display

Hello, I am experiencing an issue in displaying a data frame using st.dataframe.
The issue is that the “values” are displayed with 3 zeros after comma even if i rounded the df :

Here is the code i used :
df_cli = df.groupby([“Client”], as_index=False).agg({
‘cost1’: ‘mean’,

st.dataframe(df_cli , use_container_width=True)

i got this output display :

Can anyone help to display the values with only one or two decimals.

Thank you !

There are two pieces here: the stored value and how it’s displayed. Rounding is a computation to change the value. If you want to control how it’s displayed, you can use a dataframe styler. You can pass a styler element to Streamlit instead of the plain dataframe.

From pandas documentation:

df = pd.DataFrame([[np.nan, 1.0, 'A'], [2.0, np.nan, 3.0]])'MISS', precision=3)

Results in:

        0       1       2
0    MISS   1.000       A
1   2.000    MISS   3.000

Streamlit’s documentation has an example of passing a styler:


Hello, Thank you so much !

1 Like