Context: I’m trying to apply a backgound color change on a streamlit app on the headers and indices of a multi-index dataframe:
arrays = [
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
["one", "two", "one", "two", "one", "two", "one", "two"],
]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=[None, "Brand"])
df = pd.DataFrame(np.random.randn(3, 8), index=["A", "B", "C"], columns=index)
When using applymap_index
, this should change the background color as follows:
st.dataframe(df.style.applymap_index(lambda x: "background-color:yellow;"))
This should work because using applymap
alone inserts the background color on the cells of the dataframe, but applymap_index
which should change the index background colors doesn’t.
How can I then change the background color of the indices? (columns/headers and indices?)
Thanks