Skip to content

Conversation

@attack68
Copy link
Contributor

@attack68 attack68 commented Dec 31, 2021

This allows Styler.to_latex to also render \cline to separate sparse MultiIndex rows according to user input. Tests are also included to demonstrate functionality with hidden rows and hidden index levels.

Note that DataFrame.to_latex also uses \cline but it is forced in certain cases without options.

midx = pd.MultiIndex.from_product([["A", "-", "B"], [0], ["X", "Y"]], names=["lvl 0", "lvl 1", "last lvl"])
df = pd.DataFrame([[1, "pig"], [2, "coin"], [99, ""], [99, ""], [3, "sky"], [4, "pie"]], 
                  index=midx, columns=["int", "str"])
styler = df.style
styler.hide([("-", 0, "X"), ("-", 0, "Y")])
styler.hide(level=[1,3])
print(styler.to_latex(clines="all;index", hrules=True, multirow_align="t"))
all skip-last
index Screenshot 2021-12-31 at 14 49 53 Screenshot 2021-12-31 at 14 55 22
data Screenshot 2021-12-31 at 14 51 30 Screenshot 2021-12-31 at 14 52 59

Default render without clines:

Screenshot 2021-12-31 at 15 03 14

@jreback jreback added this to the 1.4 milestone Dec 31, 2021
@jreback jreback added IO LaTeX to_latex Styler conditional formatting using DataFrame.style labels Dec 31, 2021
@jreback jreback merged commit a393fcd into pandas-dev:master Jan 5, 2022
@jreback
Copy link
Contributor

jreback commented Jan 5, 2022

@meeseeksdev backport 1.4.x

@jreback
Copy link
Contributor

jreback commented Jan 5, 2022

thanks @attack68

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Jan 5, 2022
@lumberbot-app
Copy link

lumberbot-app bot commented Jan 5, 2022

Something went wrong ... Please have a look at my logs.

jreback pushed a commit that referenced this pull request Jan 6, 2022
@attack68 attack68 deleted the styler_latex_cline branch January 7, 2022 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IO LaTeX to_latex Styler conditional formatting using DataFrame.style

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Styler.to_latex()

2 participants