Skip to content

ENH: Pipe attrs to_html Jinja2 environmental variables #59193

@disarticulate

Description

@disarticulate

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

Dataframe and Styler implement a .to_html function which allows using custom styles via jinja2 custom templates which can be accessed via https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.io.formats.style.Styler.from_custom_template.html

Templates exposes each cell as a dict in the format of:

{'type': 'td', 'value': '0.004', 'class': 'data row3 col4', 'is_visible': True, 'attributes': '', 'display_value': '0.004', 'id': 'row3_col4'}

Dataframes and Series appear to implement the necessary but ???:

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.attrs.html#pandas.DataFrame.attrs
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.attrs.html#pandas.Series.attrs

Though it's not clear these are the same things.

I'm trying to pipe a jupyter notebook to html, then from html pandoc it to Docx. This requires being able to set a attribute=value defined as custom-style="Footnote Text", which allows Pandoc to apply a docx style.

Feature Description

Figure out how to either add attributes from the series or dataframe or implement a Styler component which adds attributes which get put into the jinja2 template. It's clear this was intended, but not implemented.

Alternative Solutions

The alternative would have me making custom templates for every table I need, rather than allowing pandoc to naturally adapt styles

Additional Context

I could probably implement this feature but it's obfuscated how the render goes from accessing a cell and putting that into a render function.

I assume it can be a mirror image of the set_table_styles function and instead but set_table_attributes unless the intention was to use the Dataframe.attrs or Series.attrs.

Either way, some clear direction could get this implemented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementIO HTMLread_html, to_html, Styler.apply, Styler.applymapNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions