-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: index naming escaping not performed by Styler.format_index
#47489
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
Comments
Adding a few comments since I'm running in the same issue here (specifically I'm summarizing the results of some simulations and the names of the variables/scores I'm using contain many underscores and I'm exporting to LaTeX).
A working fix is the following: from pandas.io.formats.style_render import _escape_latex
# assume your DataFrame is df
for level in range(df.index.nlevels):
if df.index.get_level_values(level).name is not None:
df.index.set_names(_escape_latex(df.index.get_level_values(level).name), level=level, inplace=True)
for level in range(df.columns.nlevels):
if df.columns.get_level_values(level).name is not None:
df.columns.set_names(_escape_latex(df.columns.get_level_values(level).name), level=level, inplace=True) Installed versionsINSTALLED VERSIONS ------------------ commit : a671b5a python : 3.10.6.final.0 python-bits : 64 OS : Darwin OS-release : 21.6.0 Version : Darwin Kernel Version 21.6.0: Thu Nov 9 00:42:05 PST 2023; root:xnu-8020.240.18.705.10~1/RELEASE_ARM64_T6000 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.1.4 |
Thanks for the info. Note that this solution cannot be incorporated into Styler as a PR because it breaks the design objective of the styler as it modifies the DataFrame directly. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
e.g. see https://stackoverflow.com/questions/72716879/is-there-a-function-to-format-the-index-name-in-a-pandas-styler-dataframe-style
Escaping is applied to formatted header cells but not to index name cells.
Expected Behavior
Unknown at this point, perhaps will work just to apply the same escape parameter to the index name but have to evaluate first.
Installed Versions
Replace this line with the output of pd.show_versions()
The text was updated successfully, but these errors were encountered: