Skip to content

ENH: allow convert_css in Styler.to_latex to parse css classes set with set_td_classes and set_table_styles #48038

Open
@vnmabus

Description

@vnmabus

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wanted to make a function to create and format a table with experiment results. However I am facing some problems due to the way Pandas actually works:

  • It is impossible to actually return an styled DataFrame as far as I know, one must return a Styler object instead. Thus, users must know about the Styler class, and it also has a bad text representation in terminal.
  • The most flexible approach to styling is to set CSS classes (for example, a class for a significant result) and then add styling to the classes. This is again problematic for several reasons:
    • There is no analog of set_td_classes for index and column titles, that is, a set_th_classes or something like that.
    • Although the classes with a posterior call to set_table_styles work well for HTML output, when a user has to format the table for a publication (with to_latex), the style for the classes is not applied. Instead the CSS selector and properties are prepended to the Latex output. This occurs even when using convert_css and we restrict ourselves to the supported CSS conversions.
  • I wanted to append an asterisk to cells of some class, but I was unable to do it. I tried both of the ways here but they did not work (or I did it wrong somehow).

Feature Description

  • (Optional): Allow to set the styler object for a particular DataFrame.
  • Improve Styler text representation.
  • Allow to set per-CSS-class styles that work for Latex output (ideally, also allow for styles that work for both HTML and Latex).
  • Allow to append/prepend text (or maybe something more general) to both HTML and Latex outputs based on the CSS class.

Alternative Solutions

The only "solution" I was able to implement was to include the desired output as a parameter and doing things differently for each, without using CSS classes in the Latex case, and even manually changing the text of cells (which is not ideal).

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementIO LaTeXto_latexStylerconditional formatting using DataFrame.style

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions