Skip to content

ENH: View a data frame as a table with colored backgrounds #6009

Closed
@8one6

Description

@8one6

In Excel, it's very common to add conditional formatting to a range of data (either a single column, or a 2-d table). In newer versions of Excel, there are handy buttons to apply a full gradient as a background color to a range of data to highlight high and low values.

I wonder if we can easily provide a similar kind of functionality for Pandas. Two general strategies immediately came to mind for me, and I'm sure there will be other suggestions, too. But just to get the ball rolling:

  1. We could provide a DataFrame method (maybe one for Series, too) that produces a Matplotlib heatmap with overlaid values as text. See:
    http://stackoverflow.com/a/11918066/2501018
    http://stackoverflow.com/a/21167108/2501018

  2. (I really have no idea if this is possible, but just to throw it out there...) We could augment the HTML representation of a DataFrame to include the ability to use background colors for certain cells of the table.

It seems like either way there would be some general questions to answer/functionalities to provide:
-Color all cells, or just certain columns/rows?
-Color based on value or based on an arbitrary function of value (for example abs)
-Color cells in relation to their own column/row or in relation to all values in the table

What do you guys think? Is this a general enough problem to merit a solution within Pandas? Or is this perhaps something better suited to Matplotlib? Or should I just write functions that accept DataFrame input and create Matplotlib output in line with the SO posts above?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions