【发布时间】:2023-01-20 11:44:08
【问题描述】:
我希望根据两个功能创建自己的样式条件:我想要背景颜色和大小 row_height 。
为此,我定义了 2 个样式函数
def resistance(s):
color='#fcdcdc' if s.interpretation=='Resistant' else ''
return ['background-color: {}'.format(color)]*len(s)
def null_row(s):
size=1px if s.interpretation=='' else size=12px
return ['line-height: {}'.format(color)]*len(s)
df_style=df.style.\
apply(resistance,axis=1).\
apply(height,axis=1)
st.table(df_style)
st.dataframe(df_style)
除了 line_height 永远不会为空行更改并且似乎不起作用(没有错误消息)。当我采用任意非空条件或尝试将每个行高调整为 1px 时,情况也是如此。
streamlit 或我的代码有问题吗?
感谢帮助
【问题讨论】:
-
你能分享一个更完整的代码sn-p吗?
标签: python pandas styles streamlit