Streamlit pretty styled dataframes part 1: using the pandas Styler

Published:


Streamlit and the pandas Styler object are not friends. But, we will change that!

Towards Data Science

I have always been a fan of the styler method in pandas. When I started building Streamlit apps, it was clear to me that I wanted to style my dataframes to aid in visualising dataframes, but… surprise! As of the time of writing, Streamlit st.dataframe() doesn’t support styler objects, only dataframe objects. Well, correction, it does support them, but the UI display is horrendous!

This is why I want to share with you my workarounds and ideas to building a well-styled dataframe in Streamlit. We will cover:

  1. How to add commas for separating thousands in numbers.
  2. How to display a number as a percentage (from 0.24 in the data to 24% in the UI)
  3. How to add currency symbols.
  4. How to add colour to the cells. Even better, I will share with you my favourite colour-grading function.
  5. How to add emojis! Yes, we cant live without emojis 😊!

Streamlit is actually pretty good at inferring the best display based on data types. Imagine the…

Related Updates

Recent Updates