I want to add a column in a dataframe that shows something like a percentage increase/decrease based on some of the other columns values, and I was wondering if I can use st.metric for that in every single cell of that column?
st.metric isn’t a data type that can be saved into a dataframe; it’s a function that “does a thing” which is to render something on the front end and return its value to the back end. If you want to display something that looks like what st.metric produces, you’d have to manually do something to achieve that.
There are some styling effects in pandas you can use (like bar plot or manually styling red and green arrows), but styler support is limited in Streamlit without using the .to_html() method and doing a static rendering of the dataframe. Since font color and background color should be supported for st.dataframe, you can probably work something out with maps to convert a column to strings, appropriately append arrows, and color each cell’s font as desired.
Aggrid is also available but I would have to defer to others about what’s available and how to do it.
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.