I have been searching about thicken gridlines of a dataframe using DataFrame.style attribute. But this is not possible at all, because all the focus is on the content.
So, I tried to search if there’s something streamlit allows us to do to thicken some specific gridlines, 'cause I think it’s a good tool for data visualization.
Do I understand correctly that you’d want to use st.dataframe and have a way to thicken certain cell grids within the dataframe? I’m not sure this has been raised a lot. But generally, we are conscious that supporting pandas Styler would be a great addition!
That’s it, @arnaud. At this moment, I’ve got a dataframe with 3 columns for each month of the year. So, every column gridline from the last column of a month and beginning of the other month column, I’d like to thicken it, so that we can visualize better everytime a month data ends and starts another.
But, yeah, supporting Styler would be great. Although it would still not fit my purposes right now, 'cause pandas really doesn’t do it. So, that’s why I’m asking about this kind of edit tool in a st.dataframe.
I see! Passing this to the product team, but I’m not sure this is a very common request. By the way, you can always hack that using custom CSS with st.table (Markdown/HTML tables)
import streamlit as st
# Useful CSS to change the line thickness
st.markdown("""
<style>
table {
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 8px;
}
th:nth-child(3n), td:nth-child(3n) {
border-right: 3px solid black; /* Add thicker border to every third column */
}
</style>
""", unsafe_allow_html=True)
# That's just to show a table. You should probably use `st.table(df)`
# if you are using a Pandas dataframe instead.
st.markdown("""
| January | | | February | | | March | | |
|-------------|----------|----------|-------------|----------|----------|-------------|----------|----------|
| Item A | Item B | Item C | Item D | Item E | Item F | Item G | Item H | Item I |
""")
Man, that’s really good. Thanks, @arnaud, for your time. I’ll try this now. But I’d really like not lose all this glamor st.dataframe has. But we, streamlitters, are growing and I’m sure this will be supported soon. Thanks a lot, again.
Maybe a compromise is to try highlighting those columns differently using Pandas Styler which is supported by st.dataframe. I just tried having light background colors every three columns… Looks decent too!
def color_background(df):
bg_colors = []
color = 'background-color: #ffffff'
for col in df.index:
if '%' in col:
color = 'background-color: #e8fbff' if color == 'background-color: #ffffff' else 'background-color: #ffffff'
bg_colors.append(color)
return bg_colors
df19_styled = df18_monthly.style.apply(color_background, axis=1)
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.