如何在streamlit中使用python数据框样式

Vis*_*H K 9 python styling dataframe streamlit

我使用以下代码设置了数据框的样式:

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)
Run Code Online (Sandbox Code Playgroud)

但它不适用于streamlit。那么,知道如何在 Streamlit 上设置数据框的样式吗?

数据框的图像

谁能帮我?

小智 0

您需要将样式化的数据帧传递给 Streamlit。

st.dataframe(df2)
Run Code Online (Sandbox Code Playgroud)