I’d like to center the cell values of a dataframe, however, I’d like to do it dynamically.
I can kinda center the values like this:
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)
st.dataframe(df.style.format("{:.0f}".center(30)))
To get this:
But if I stretch the column it no longer stays centered:
So how can I center the values dynamically? And how can I also center the indices (for the headers/columns as multi-index as well)?
Thanks