Skip to content

Styler.hide_columns does not work #751

@unsolicitedcrap

Description

@unsolicitedcrap

Summary

The Styler.hide_columns method does not hide the passed in column.

Steps to reproduce

# Create test dataframe
df = pd.DataFrame({'id': np.linspace(0, 9, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
               axis=1)

# Create color dictionary
color_dict = {0:'red',2:'red',3:'lime',6:'red',7:'lime'}

# Function to color rows
def highlight_rows(s):
    if s['id'] in color_dict:
        return ['background-color:{}'.format(color_dict[int(s['id'])])]*len(s)
    else:
        return ['background-color:{}'.format('white')]*len(s)

# Color rows and hide the id column
st.sidebar.dataframe(df.style.apply(highlight_rows, axis=1).hide_columns(['id']))

Expected behavior:

DataFrame id column is hidden

Actual behavior:

DataFrame id column is visible

Additional information

The columns are hidden as expected when not using streamlit


Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:st.dataframeRelated to the `st.dataframe` elementfeature:st.tableRelated to the `st.table` elementtype:enhancementRequests for feature enhancements or new features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions