How to hide the first column in dataframe

Hi,

I tried to drop, but df.drop seems to work only on the “regular” columns. Also tried df.style.hide_index(), but no effect.

Want to hide that incrementing number first column when you do st.write(). How to do that?

Thanks!

Hi! I think this documentation covers your question: Hide row indices when displaying a dataframe - Streamlit Docs

Hope it helps!

1 Like

Hello,

Oh I see. So it’s not as straight forward as I thought.

The example worked, it hid the values. But not the column itself. So there’s a blank column with no values, like this:

------------------------
|      | col1  |col2   |
------------------------
|      | aa    |bb     |
|      | cc    |dd     |

Thanks!

That’s weird, for me it looks exactly as in the documentation.
Maybe update the streamlit version?

Can you share the dataframe (first 5 rows) and code you’re using?

here goes:

   records = [{'tt': 'abc', 'xx': 'xyz'}, {'tt': '111', 'xx': '222'}]   
   df = pd.DataFrame(records)

   # CSS to inject contained in a string
   hide_dataframe_row_index = """
            <style>
            .row_heading.level0 {display:none}
            .blank {display:none}
            </style>
            """
   st.markdown(hide_dataframe_row_index, unsafe_allow_html=True)

   st.dataframe(df)

thx.
df

hello ,

i looked at the example again and so it seems, st.dataframe will show that blank column.

st.table will remove it.

it is what it is. :slight_smile:

thank you!

1 Like

What if I want to use st.dataframe and not show the blank column? @sebastiandres @jeisma

1 Like

+1. Traced exactly the steps above in the thread and wound up at the same (unsatisfactory) place.

df = pd.read_csv('notes_and_reports/31_Days/available_days.csv', header='infer', index_col=None)

# show df without index
df = df.fillna('')
# CSS to inject contained in a string
hide_dataframe_row_index = """
            <style>
            .row_heading.level0 {display:none}
            .blank {display:none}
            </style>
            """

# Inject CSS with Markdown
st.markdown(hide_dataframe_row_index, unsafe_allow_html=True)
st.dataframe(df)


I want to get rid of the index column.
Seems like this should be easier. Streamlit 1.9.2, Python 3.8.5.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.