如何在Streamlight中更改熊猫数据帧中的行颜色



如何在Streamlit中更改pandas数据帧中的行的颜色?

我使用的是浅色背景,我想把黑色作为行的颜色。

import pandas as pd
import numpy as np

# Seeding random data from numpy
np.random.seed(24)

# Making the DatFrame
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), 
columns=list('BCDE'))], axis=1)
# DataFrame without any styling
print("Original DataFrame:n")
print(df)
print("nModified Stlying DataFrame:")
df.style.set_properties(**{'background-color': 'black',
'color': 'green'})

使用此代码,您可以将数据帧的背景颜色设置为黑色,文本颜色设置为绿色

我花了几个小时试图在数据集中给一个该死的单词上色,但没有任何结果。然后我发现可以在流媒体页面中插入CSS!因此,您只需要检查如何归档您想要在源代码中查找的结果,以找到您需要的类。

对于我的流媒体页面中一行的背景颜色,我可以这样做:

st.markdown('<style>.ReactVirtualized__Grid__innerScrollContainer div[class^="row"], .ReactVirtualized__Grid__innerScrollContainer div[class^="data row"]{ background:black; } </style>', unsafe_allow_html=True)

应该在你的页面上类似

在我的情况下,我只想给包含OKKO的字段上色,所以我使用了以下代码,因为Panda报告标题属性中每个字段的值

st.markdown('<style>div[title="OK"] { color: green; } div[title="KO"] { color: red; } .data:hover{ background:rgb(243 246 255)}</style>', unsafe_allow_html=True)

最新更新