首页 > 解决方案 > 如何在 Streamlit 中更改熊猫数据框中行的颜色?

问题描述

如何在 Streamlit 中更改熊猫数据框中行的颜色?

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

标签: pythonpandasstreamlit

解决方案


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'})

With this code, you can set the background color of the data frame as black and the text color: green


推荐阅读