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)