Groupby Indexes Not Showing Correctly on Webpage

Hey guys.
Im running the lastest Streamlit version.
I have a Pandas Dataframe with datetime column
When I use pd.groupby, the table is always showing the year both in the Year and Month Index
Before (streamlit == 0.81.1) it was fine

This is the code:

df.groupby(df.Date.dt.year, df.Date.dt.month).agg(Total=(‘To_sum’, ‘sum’)

Screen Shot 2021-11-07 at 21.44.09

Any clues what Im doing wrong?
Like I said, in previous versions of streamlit the indexes showed up OK.
Thanks for your help

Hi, what was the solution please? I have the same result with groupby dataframe

You have to rename your index:

df = df.rename_axis(index=['Year', 'Month'])

Thank you !

Hi Joaocassis,
Did that code work for you? I used it and tried many other options (like : df_H45.columns=[‘culture_principale’,‘culture_precedente’,‘median_0_45’]) but i got an error:
ValueError: Length of names must match number of levels in MultiIndex.
ValueError: Length mismatch: Expected axis has 1 elements, new values have 3 elements
the dataframe result of group by is fine in python and i can download it correctly
It is only in streamlit that it hide the name of headers even when i download it from my streamlit app the result is one only column wich is the calculated result of my group by
image

It seems you have a dataframe with a Multi-Index with 2 levels and a single column (median_45)

You can try to:

dataframe.reset_index()

And then rename the columns

Otherwise check pandas documentation.

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