Skip to content

ENH: Styler apply_index and format_index applicable to index names #48936

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
1 of 3 tasks
DanielGoncalves47264 opened this issue Oct 4, 2022 · 8 comments · Fixed by #57880
Closed
1 of 3 tasks

ENH: Styler apply_index and format_index applicable to index names #48936

DanielGoncalves47264 opened this issue Oct 4, 2022 · 8 comments · Fixed by #57880
Assignees
Labels
Enhancement Styler conditional formatting using DataFrame.style

Comments

@DanielGoncalves47264
Copy link

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I would love to be able to format both column names and index names when trying to export to excel.

Feature Description

Format both column names and index names when trying to export to excel.

df=pd.DataFrame()
df.style.apply_map_index_names(func:, axis,)

Alternative Solutions

There are a few modules regarding Python and Excel that I believe have this feature like StyleSheet

Additional Context

No response

@DanielGoncalves47264 DanielGoncalves47264 added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 4, 2022
@attack68
Copy link
Contributor

attack68 commented Oct 4, 2022

this has been raised elsewhere, i cant, off the top of my head, remember where.

Since Styler methods are designed to be chained it might be worth sketching out a solution where we could re-use existing methods to extend this functionality rather than add new api methods.

Something like Styler.format_index(names=True) or Styler.apply_index(names=True) makes this function applicable only to the index names rather than to the index values themselves

@attack68 attack68 changed the title ENH: ENH: Styler apply_index and format_index applicable to index names Oct 4, 2022
@attack68 attack68 added Styler conditional formatting using DataFrame.style and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 4, 2022
@tehunter
Copy link
Contributor

tehunter commented Oct 5, 2022

Something like Styler.format_index(names=True) or Styler.apply_index(names=True) makes this function applicable only to the index names rather than to the index values themselves

This is the solution I've come up with as well.

  1. Add a ctx_index_names and ctx_column_names which follow the existing ctx_* patterns.
  2. Add a axis_names bool parameter to Styler._apply_index. If True, set to the ctx_*_names dictionary.
  3. In ExcelFormatter, modify the current index_labels and columns.names sections to yield a CssExcelCell. (I've only implemented this in Excel as that's my use case, but it's probably straightforward to add it to the HTML in the _generate_col_header_row and _generate_index_names_row functions)

@attack68
Copy link
Contributor

attack68 commented Oct 5, 2022

the general approach i have adopted in the past PR wise has been first get it working for html with tests.

then a separate pr for latex woth tests and finally a pr for excel with tests.

all come in the same release, probably aiming at 1.6 now if someone has the time to do a pr.

it is probably worth it since the names are the last outstanding element that cant be formatted or styled

@tehunter
Copy link
Contributor

tehunter commented Oct 6, 2022

take

@tehunter
Copy link
Contributor

tehunter commented Oct 6, 2022

Will probably need some assistance with the HTML and LaTeX tests, but I'll get the ball rolling

@attack68
Copy link
Contributor

#47489

@Delengowski
Copy link
Contributor

Delengowski commented Dec 22, 2023

@tehunter You've lost interested in finishing? I would like to take this up if so.

@attack68
Copy link
Contributor

@Delengowski I would suggest following this up, possibly revising the PR if you can

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