Dataframe styling issue

Hi,
I’m trying to apply formatting to my dataframe to make it look nice on the display and I’ve encountered several issues, but for now I’ll just stick to the decimals formatting.

  • general decimal formatting works well for any given column, but in my case I need to format a column to various decimal places based on value (eg: value greater than 1000, no decimals, value between 1 and 1000, 2 decimal places, and value less than 1, 5 decimal places). ‘Price’ is the name of my column in this example:

st.dataframe(table.style.format({‘Price’: lambda x: ‘{:,.0f}’ if x >= 1000 else ‘{:,.2f}’ if 1 <= x < 1000 else ‘{:,.5f}’})

On the streamlit app I get on this column only the corresponding formatting, but not the values: {:,.2f}, {:,.0f} etc…

image

Does anyone know why?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.