How to center a dataframe in streamlit new version

Question:

I had no problem with the alignment in the old version but when I upgraded to the new version I saw this happen. I tried the following 3 different approach below the dataframe but none of them fixes the problem. Is there any way to work around it?
enter image description here

#Sets df size with width 1000 and height 300, but width has a limited range
st.dataframe(df, 1000, 300) 

st.dataframe(df, use_container_width=True) 

st.write(df, use_container_width=True)
Asked By: Jamiu Shaibu

||

Answers:

I ask this question for a while now but yet didn’t get any response until I figured a way to handle my problem.
I used streamlit AgGrid Component to fix my problem. AgGrid() by default will center the dataframe, it also has other awesome features of handling data frames much better than st.dataframe() and it is pretty simple and clean. I could even choose to color the data frame to my liking which I found pretty cool and interactive.

In case you face similar problem and want to take this approach I will recommend you visit streamlit AgGrid Component to know the inside of the component and how it is implimented.

from st_aggrid import AgGrid

AgGrid(df)

OUTPUT:
enter image description here

Answered By: Jamiu Shaibu
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.