I am trying to take a data frame and display it as a table.
I am using st.dataframe().
The data has a few columns that are floats, but when displaying it will automatically put commas for everything except numbers that have no decimals.
For example:
I am trying to take a data frame and display it as a table.
I am using st.dataframe().
The data has a few columns that are floats, but when displaying it will automatically put commas for everything except numbers that have no decimals.
For example:
Hi @Bobby, that is the default behavior of st.dataframe.
In what format would you like the output? Do you want:
You can customize this behavior using pandas.Styler and pass the pandas.Styler object to st.dataframe. Here’s an illustrative example answering 1. and 2.
import streamlit as st
import pandas as pd
data = {'Month' : ['January', 'February', 'March', 'April'],
'Expense':[ 21525220.653, 311258408.75, 4099, 56245263.942]}
df = pd.DataFrame(data, columns = ['Month', 'Expense'])
st.write("Default: ")
st.dataframe(df)
st.write("Commas everywhere: ")
s = df.style.format({"Expense": lambda x : '{:,.4f}'.format(x)})
st.dataframe(s)
st.write("No commas: ")
s = df.style.format({"Expense": lambda x : '{:.4f}'.format(x)})
st.dataframe(s)
Happy Streamlit-ing! 
Snehan
Thanks this helps a lot!