Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Multi-index column headers empty when 2nd level contains an empty string #9749

@Dev-iL

Description

@Dev-iL

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

When an empty string is provided for the 2nd column level, the first level is also empty. It does work correctly when the 1st level is the empty one.

Reproducible Code Example

Open in Streamlit Cloud

import numpy as np
import pandas as pd
import streamlit as st


def main():
    arrays = [
        ["bar", "bar", "baz", "baz", "foo", "foo", "qux"],
        ["one", "two", "one", "two", "one", "two", ""],
    ]
    tuples = list(zip(*arrays))
    index = pd.MultiIndex.from_tuples(tuples, names=["first", "second"])

    df = pd.DataFrame(np.random.randn(3, 7), index=["A", "B", "C"], columns=index)

    st.dataframe(df)


if __name__ == '__main__':
    import streamlit.web.bootstrap

    if '__streamlitmagic__' not in locals():
        st.web.bootstrap.run(__file__, False, [], {})

    main()

Steps To Reproduce

Run the example code.

Expected Behavior

image

Current Behavior

image

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.39
  • Python version: 3.12
  • Operating System: Win10
  • Browser: Edge

Additional Information

As a workaround, using " " instead of an empty string for the 2nd level makes the first level be shown.

Metadata

Metadata

Assignees

Labels

feature:st.data_editorRelated to the `st.data_editor` widgetfeature:st.dataframeRelated to the `st.dataframe` elementpriority:P3Medium prioritystatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions