I just tested and it seems that Streamlit’s handling and a DataFrame Styler is not correclty handling df.style.hide(axis="index"). I would think that would be the best way to do it but alas:
import streamlit as st
import pandas as pd
df = pd.DataFrame({'A':[1,2,3],'B':['a','b','c']})
st.dataframe(df)
st.dataframe(df.style.hide(axis="index"))
st.markdown(df.style.hide(axis="index").to_html(), unsafe_allow_html=True)
That being the case, the Streamlit Documentation does tell you exactly the CSS trickery to accomplish this:
Edit: I see a note that that doesn’t work past version 1.10, and that I also skipped over where you already linked to it. Oops. The modern implementation is a lot less receptive to CSS hacks, but I’m fiddling.
Yeah, I think it’s going to be hard to accomplish it through the st.dataframe method. The interactivity makes it much more complicated. It’s easy enough to accomplish with a static table as shown above, but interactive options haven’t come out pretty for me.
I tried converting to a plotly go.Table, but that only allows dragging and dropping columns without sorting.
I tried itables, and that does work, but it needs a lot of css styling to make it pretty.
Sorry I don’t have anything slick, but I think it’s worth raising a bug on GitHub if it’s not there already being that officially Streamlit is supposed to respect a pandas styler.
Thanks for your efforts. It is a little frustrating as this is usually a standard feature of these types of controls/ objects from my experience. The Streamlit app is only a temp solution until a more appropriate solution can be developed in one of our business systems. I will likely vote on the GitHub issue.
Hey @Nathan_Johnston,
I will admit I am quite new to python and streamlit, so apologies if this is not an ideal solution, but I got around this by setting my first column as the index instead.
import streamlit as st
import pandas as pd
df = pd.DataFrame({'A':[1,2,3],'B':['a','b','c']})
st.dataframe(df)
st.dataframe(df.set_index(df.columns[0]))
@jmilno this works as expected for me. would be great if this behavior was controlled by a feature of st.dataframe (like st.dataframe(hide_index=True) .
One note, doing this for some reason doesn’t work but your method does.
df.set_index(df.columns[0])
st.dataframe(df)
#still shows index
I’ll note that ideally this should work both in rendering the dataframe in Streamlit but also downstream to exporting the file via
We released a lot of new configuration options for st.dataframe and st.data_editor in 1.23. This also includes the hide_index parameter that lets you easily hide the index:
import streamlit as st
import pandas as pd
df = pd.DataFrame({'A':[1,2,3],'B':['a','b','c']})
st.dataframe(df, hide_index=True)
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.