I’m working on an app to track grants, and I had some questions which IMHO should be very basic (and common) but I couldn’t find the answers anywhere. So here goes:
I’d like to format some numbers in a st.dataframe. I know I can do this in the pandas data frame, but I’d prefer not to so that I can sort correctly in the UI.
Anyway, here’s what I’d like to format:
Currency amounts with a leading $, two decimal places AND a comma separator at the thousands place.
Percents to one decimal place and a percent sign at the end.
I’d imagine these are pretty easy, and if I may suggest, could we add some of these to the docs?
Thanks for your help!!
There is a format argument to NumberColumn. It is poorly documented (to say the least) and apparently pretty limited, but AFAIK that is all you have.
You could also use pandas styles but that would mess up the sorting in the UI unles you add leading zeros. I think that is what you mean in the second paragraph.
Tha only documentation I am aware of is in the link above. You can search the internet for printf (but that is C and this is probably some JS library that doesn’t work exactly the same), do some trial and error and see how far it gets you.
@Goyo I think you’ve hit on the issue that I’m having. Streamlit doesn’t really follow any one standard for this. I can’t imagine I’m the only person who has run into this issue.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.