pythonpandasstreamlitpandas-styles

How to hide dataframe index on streamlit?


I want to use some pandas style resources and I want to hide table indexes on streamlit.

I tryed this:

import streamlit as st
import pandas as pd


table1 = pd.DataFrame({'N':[10, 20, 30], 'mean':[4.1, 5.6, 6.3]})
st.dataframe(table1.style.hide_index().format(subset=['mean'],
             decimal=',', precision=2).bar(subset=['mean'], align="mid"))

but regardless the .hide_index() I got this:

enter image description here

Ideas to solve this?


Solution

  • Documentation for st.dataframe shows "Styler support is experimental!"
    and maybe this is the problem.

    But I can get table without index if I use .to_html() and st.write()

    import streamlit as st
    import pandas as pd
    
    df = pd.DataFrame({'N':[10, 20, 30], 'mean':[4.1, 5.6, 6.3]})
    
    styler = df.style.hide_index().format(subset=['mean'], decimal=',', precision=2).bar(subset=['mean'], align="mid")
    
    st.write(styler.to_html(), unsafe_allow_html=True)
    
    #st.write(df.to_html(index=False), unsafe_allow_html=True)
    

    enter image description here