Skip to content
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

BUG: Styler.hide_columns() does not hide index name row #42101

Closed
attack68 opened this issue Jun 18, 2021 · 9 comments · Fixed by #42839
Closed

BUG: Styler.hide_columns() does not hide index name row #42101

attack68 opened this issue Jun 18, 2021 · 9 comments · Fixed by #42839
Assignees
Labels
Bug good first issue Styler conditional formatting using DataFrame.style
Milestone

Comments

@attack68
Copy link
Contributor

attack68 commented Jun 18, 2021

Whilst Styler.hide_index() hides column header name (along with the index), the index name row persists when Styler.hide_columns() is used to hide column headers.

The index names rows should also be hidden, since currently there is no way to hide it independently.

What to do:

  1. Find pandas/io/formats/style_render.py
  2. Find the method for the StyleRenderer called _translate_header and read the documentation what it is trying to structure.
  3. Go to the section in the method labelled # 2 and insert self.hide_columns_ into the conditional.
  4. Add a test to pandas/tests/io/formats/style/test_style.py that addresses this.
@attack68 attack68 added Bug Styler conditional formatting using DataFrame.style labels Jun 18, 2021
@attack68 attack68 added this to the Contributions Welcome milestone Jun 18, 2021
@raghuabhishek
Copy link
Contributor

take

@skvrahul
Copy link
Contributor

Can a user not call Styler.hide_index().hide_columns() to achieve this?
As they both are separate configurations?

@attack68
Copy link
Contributor Author

Can a user not call Styler.hide_index().hide_columns() to achieve this?
As they both are separate configurations?

if hide_index is called the index name row is hidden, but that is not the point. The user should be able to call hide_columns and the index name row should be hidden without the necessity of also having to hide the index-labels.

Note the difference between the name of the index, and the actual index-label values.

@raghuabhishek
Copy link
Contributor

Hi @attack68, Can you please give an example for better understanding of this issue.

@skvrahul
Copy link
Contributor

The user should be able to call hide_columns and the index name row should be hidden without the necessity of also having to hide the index-labels.

@attack68 this already seems to be the case for me on the master branch

> df = pd.DataFrame({'A': np.random.randint(50, size=10), 'B': np.random.randint(50, size=10)})
> df.style.hide_columns() 

0	34	47
1	3	35
2	0	18
3	23	11
4	17	35
5	17	15
6	1	39
7	36	9
8	15	18
9	4	7
.....

am I missing something?

@raghuabhishek
Copy link
Contributor

Hi @skvrahul how did you get the dataframe as an output after executing this line "df.style.hide_columns()" . For me its returning a styler object. Did u typecast? If yes, how?

@skvrahul
Copy link
Contributor

Hi @skvrahul how did you get the dataframe as an output after executing this line "df.style.hide_columns()" . For me its returning a styler object. Did u typecast? If yes, how?

Running it in a Jupyter Notebook should output a table by rendering the underlying HTML.

@attack68
Copy link
Contributor Author

@skvrahul @raghuabhishek you both seem to be confused by the name of an index and the values of an index, be it, a row-index or a column-index. The mentioned documentation in the OP should clarify this also, but here is a screenshot of the issue on master:

Screen Shot 2021-06-22 at 07 25 34

@skvrahul
Copy link
Contributor

Yeah this clears things up. Thanks!

Looks like I missed naming the index in my example, which threw me off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug good first issue Styler conditional formatting using DataFrame.style
Projects
None yet
4 participants