-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: add kwargs rename
to Styler.format_index
for overwriting index labels
#45288
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
Conversation
ok so is the plan to deprecate |
3 small arguments for use case: First, progressing Second, the existing IO methods have this Finally, in a more specialised scenario you might want a formatter that uses a loop index, or combines all level values simulatneously to determine an alias, which you then pass directly here. Note that the indexing of the data can still be maintained underneath via the MultiIndex.
|
…_multi # Conflicts: # doc/source/whatsnew/v1.5.0.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not objecting to the need to do this, i get it. but we don't use alias
anywhere; why isn't this just .rename()
?
Didn't really feel this warranted its own method when all other index formatting is done within But im not tied to anything; you tell me which you prefer and ill make changes... |
…_multi # Conflicts: # doc/source/whatsnew/v1.5.0.rst
@jreback what about a different kwarg other that |
aliases
to Styler.format_index
for overwriting index labelsrename
to Styler.format_index
for overwriting index labels
…_multi # Conflicts: # pandas/io/formats/style_render.py
@@ -1203,6 +1207,17 @@ def format_index( | |||
Convert string patterns containing https://, http://, ftp:// or www. to | |||
HTML <a> tags as clickable URL hyperlinks if "html", or LaTeX \href | |||
commands if "latex". | |||
rename : list of str, list of list of str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
umm the user can simply .rename_axis
on the frame no? why adding api here that is duplicative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my design objective with styler has been to customise the display of tables without altering the underlying dataframe object (which is of course possible to get around many of the styler functions).
you can lose the power of indexing if you relabel for the purpose of printout.
additionally, methods like DataFrame.to_html
and DataFrame.to_latex
use a headers
argument which does this relabelling. So in order to replicate that behaviour with the styler code need this pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback feels like this one has stalled and getting push back anyway. If poss please take one last look since it factors into the PRs where I convert the |
…_multi # Conflicts: # pandas/tests/io/formats/style/test_format.py
@attack68 circling back around on this. |
In order to be able to completely re-write |
@attack68 i am sympathetic here as i know you want to make this fully compatible with the existing formaters. The issues i have here are:
I agree that this could be viewed as on the line, but its much nicer to keep this api nice and tight and use the existing fluent api to solve this problem. I see that we already have styler methods to do some index manipulation e.g. https://pandas.pydata.org/pandas-docs/dev/reference/api/pandas.io.formats.style.Styler.format_index.html?highlight=styler ( |
@jreback, OK, yes I see your point, |
In methods such as
DataFrame.to_latex
andDataFrame.to_html
theheader
keyword arg was implemented to provide aliases for column headers, instead of using the underlying DataFrame labels.Currently
Styler.format_index
allows adding a generic formatter to change the display of index labels but this is not an easy way to simply provide a list of string aliases to use instead. PR adds this function, which will simplify the transition of the above methods to Styler implementation.