Display multi-index columns as merged cells when printing a dataframe

Context: I’m using streamlit to display a dataframe on a small web-app and I have a multi-index column. Let’s say we have this 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)

Printing the dataframe on python it displays this:


Which is the wanted results.

However, when I display the same dataframe using streamlit st.dataframe(df) it looks like this:

How can I make it so that the multi-index columns on the first level are not repeated? I essentially would like them to be merged in a single cell in streamlit


Hi @roo,

Thanks for posting. There’s an open GH issue here for this issue – feel free to comment/share your thoughts in the thread!