I have styled my dataframe using the below code: th_props = [ ('font-size', '14px'), ('text-align', 'center'), ('font-weight', 'bold'), ('color', '#6d6d6d'), ('background-color', '#f7ffff') ] td_props = [ ('font-size', '12px') ] styles = [ dict(selector="th", props=th_props), dict(selector="td", props=td_props) ] df2=outputdframe.style.set_properties(**{'text-align': 'left'}).set_table_styles(styles) But it doesn't work on streamlit. So, any idea how to style the dataframe on streamlit?
Drop files here
or click to upload
import streamlit as st
import pandas as pd
# Create a sample dataframe
data = {
'Column 1': [1, 2, 3, 4],
'Column 2': [5, 6, 7, 8],
'Column 3': [9, 10, 11, 12]
}
df = pd.DataFrame(data)
# Style the dataframe
def style_dataframe(df):
return df.style.set_properties(**{'text-align': 'left'})
# Table styles
table_styles = [
{'selector': 'th', 'props': [('font-size', '14px'), ('text-align', 'center'), ('font-weight', 'bold'), ('color', '#6d6d6d'), ('background-color', '#f7ffff')]},
{'selector': 'td', 'props': [('font-size', '12px')]},
]
styled_df = style_dataframe(df).set_table_styles(table_styles)
st.markdown('### Using `st.table`')
st.table(styled_df)
st.markdown('### Using `st.dataframe`')
st.dataframe(styled_df)
st.markdown('### Using `st.write`')
st.write(styled_df)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?