Hide row indices when displaying a dataframe in Streamlit v1.16.0

How do I hide the indices in a dataframe in Streamlit v1.16.0?

A previous post here showed how to achieve this in an earlier version of Streamlit: Hide row indices when displaying a dataframe - Streamlit Docs

I can’t seem to find a solution here, and I would have thought this would have been a pretty standard activity conducted on dataframes

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)

image

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.

import itables

df=pd.DataFrame()

st.components.v1.html(itables.to_html_datatable(df), height=400)

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.

Here’s a GitHub issue you can vote on:

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.

Thanks again for your assistance

1 Like