How to center columns

hi, i am trying to get a dataframe with columns center so I did:

st.dataframe(sum_stat_perf
                     .style
                     .set_properties(**{"background-color": "white", "color": "black", "border-color": "black", 'text-align': 'center'})
                     .format("{:.2f}%", subset=(['Taux sans risque', 'Ann. return', '% Rdt>0', 'Average up', 'Average Down',
                                                 'Perf 2023', 'Perf 2022', 'Perf 2021', 'Perf 1 an', 'Perf 3 ans', 'Perf 5 ans'],
                                                slice(None))
                             )
                     .format("{:.2f}%", subset=(['Up ratio', 'Down ratio'],
                                                ['portef', 'indice'])
                             )
                     .format("{:.2f}", subset=(['Skewness', 'kurtosis'],
                                               slice(None))
                             ),
                     use_container_width=True,
                     height=660
                     )

but it seems that the 'text-align': 'center'did nothing.

Thx for your help.

Officially, styler support is experimental with only color and value explicitly available. You can convert your styler to html with the .to_html() method and then render it directly, but that would lose the interactivity.

import streamlit as st
import pandas as pd

df = pd.DataFrame({
    'A':[1,2,3,4],
    'B':[1111,2,33,44444],
    'C':[1,2,3,4]
})

styled_df = df.style.set_properties(**{
    "background-color": "white", 
    "color": "black", 
    "border-color": "black", 
    'text-align': 'center'
})

st.dataframe(styled_df)
st.write(styled_df.to_html(), unsafe_allow_html=True)

image

If there are specific aspects of styler you would like supported, I recommend checking GitHub for a current feature request to vote on or creating a new feature request so the devs can be aware of and track interest.

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