Skip to content

QST: What is the use of cell_context in the Styler? #35998

Closed
@grantstead

Description

@grantstead
  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.


Question about pandas

Note: If you'd still like to submit a question, please read this guide detailing how to provide the necessary information for us to reproduce your question.

In pandas/io/formats/style.py (

cell_context = dict()
) the cell_context dict is created (empty). It is referenced twice (on line 318 and 382), where values are accessed, if they are present. The dict is however never updated.

What is the use of this variable? It seems to me to be quite useless as there is no way to set it's content. Is it purely there for future use? I use v0.23 where it was already like this, so I expected it to have changed in master, but this doesn't seem to be the case. Is there some way of setting it that I'm not aware of?

There are a few stack overflow questions (https://stackoverflow.com/questions/55236631/add-custom-css-class-to-column-or-cell-of-a-dataframe and https://stackoverflow.com/questions/62075616/add-style-class-to-pandas-dataframe-html) )by others,s not me) that ask how to set the class of a cell. These seem related to how this dict's values could be set. To "implement" support for classes, I simply overwrote the render method to call _translate and then to adjust the d["body']'s content where I added to the cell's class value. If cell_context could be set, then there would be no need to do this overriding after the fact (and actually benefit from the looking that is performed against cell_context)... (I would like to respond to these two questions, possibly with my monkey-patching, but preferably with what happens in _translate()).

Thanks,
Grant

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stylerconditional formatting using DataFrame.styleUsage Question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions