Skip to content

New Feature Request: df.style.hide_index() to hide a particular index level #25475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
samcha1996 opened this issue Feb 28, 2019 · 8 comments · Fixed by #42636
Closed

New Feature Request: df.style.hide_index() to hide a particular index level #25475

samcha1996 opened this issue Feb 28, 2019 · 8 comments · Fixed by #42636
Labels
Enhancement MultiIndex Styler conditional formatting using DataFrame.style
Milestone

Comments

@samcha1996
Copy link

Problem description

The present implementation of df.style.hide_index() removes the complete index while rendering html.
It would be better to have an optional input of index level and hide only that index level while rendering.
example df.style.hide_index(level=1)
It provides more option and flexibility to user.

Sorry to post this as an issue, but I didn't find any option for suggesting new features.

@TomAugspurger
Copy link
Contributor

Sorry to post this as an issue, but I didn't find any option for suggesting new features.

An issue is fine for feature requests, but we need a simple example what the request is.

@TomAugspurger TomAugspurger added the Needs Info Clarification about behavior needed to assess issue label Feb 28, 2019
@samcha1996
Copy link
Author

In[15]: df
Out[15]: 
                0         1         2         3
bar1 one  0.624257 -1.919695 -0.608513  1.460487
bar2 two -0.609755  0.874438  0.169402 -1.236653
baz1 one  0.694922  0.585993 -0.871894 -0.240299
baz2 two -0.158941 -1.604056 -0.517174  0.551289
foo1 one -1.606837  1.009960 -1.026319  1.377517
foo2 two -1.062810 -0.041552 -0.423098  0.438010
qux1 one  1.082581  0.182992 -1.910832  0.156215
foo2 two -0.255548  0.419918 -0.668972 -0.586820

Now doing df.style.hide_index().set_table_attributes('border=1').render() and opening in browser gives
https://www.w3schools.com/code/tryit.asp?filename=G1MGWU5COD4H.
Open the link and press run.

I want that there should be an option for level in hide_index() like
df.style.hide_index(level=1).set_table_attributes('border=1').render() which gives output like
https://www.w3schools.com/code/tryit.asp?filename=G1MH0SRAWPMS
Open the link and press run.

@TomAugspurger
Copy link
Contributor

Thanks. Note that MultiIndex support in .style is pretty limited right now. It doesn't look especially easy to add this to the current implementation.

@TomAugspurger TomAugspurger added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap MultiIndex Difficulty Intermediate and removed Needs Info Clarification about behavior needed to assess issue labels Feb 28, 2019
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Feb 28, 2019
@samcha1996
Copy link
Author

Okay. Just thought that it would be a good to have feature in pandas.style .
Thanks

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Feb 28, 2019 via email

@samcha1996
Copy link
Author

Yeah of course i would love to work on it. And I would also like to know more about the implementations of pandas too.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Feb 28, 2019 via email

@samcha1996
Copy link
Author

Great. Thanks for the quick response.

@mroeschke mroeschke added Styler conditional formatting using DataFrame.style and removed IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string labels Jun 27, 2021
@jreback jreback modified the milestones: Contributions Welcome, 1.4 Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement MultiIndex Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants