Dataframe widget columns widht problem

Hello

I noticed a problem on the dataframe widget regarding the width of the columns

If the length of the dataframe is < 5 the headers are displayed in full
the most surprising is that if we first display a dataframe with a length < 5 and update the display, we keep the names of the columns in full

Is it due to the recent update?
Is there a way around the problem without using table or aggrid or plotly table?

Below is the code to reproduce this problem

import pandas as pd
import streamlit as st

L = list(range(100))
d = {'AAAAAAA': L,
     'BBBBBBB': L,
     'CCCCCCC': L,
     }
df = pd.DataFrame(d)
c1,c2 = st.columns(2)

c1.dataframe(df[:5])
if not c2.button("Increase len"):
    c2.dataframe(df[:4])
else : 
    c2.dataframe(df)

thank you in advance

Hey @Egos,

Thanks for reporting this issue. The technical reason for the difference is that there is an outlier detection built into the automatic sizing algorithms that kicks in at > 5 rows. The column size is calculated by taking the maximum width of the largest cell, but outliers (with a lot larger width than all other cells) are ignored. That’s why the header is ignored here. But there are some improvements we could implement for the automatic sizing algorithms. We might also add an option to configure the width of a column manually as well.

The old st._legacy_dataframe or st.table might be a temporary alternative here as well.

2 Likes

Thanks for the advice st._legacy_dataframe do the job perfectly
i’m afraid that the new dataframe system is so … useless
streamlit is a great tool but industry have a high requirement for table formatting