Skip to content

CSS selector for index cells #28204

Closed
@kelmouloudi

Description

@kelmouloudi

While using Jupyter notebooks, I like to change the color of header cells in Pandas dataframes (all index cells, up and left) for more contrast between the indexes and the data itself (especially when I'm dealing with multiple indexes after using .groupby() like in the picture below) :

example

I used to achieve this using this CSS code :

%%HTML
<style> 
.dataframe th {
background: #3f577c ;
font-family: monospace ;
color: white ;
border: 3px solid white ;
text-align: left !important ; } 
</style>

This worked because every index cell (in all indexes, up and left) used to be represented by a <th> </th> HTML tag.

However, after updating to Pandas version 0.25.1 from version 0.21.x, the CSS stopped working because the HTML changed so only the upper index cells (column names) are wrapped in <th> <th> tags. The left index simply uses <td> </td> tags, just like the data cells (See image below. Note that both Genre and MediaTypeId are indexes):

example

Was this intentional? I tried using first-child like below but it only worked with dataframes having only 2 indexes (up and left). For the dataframes with more than one index on the left, only the first index is affected :

%%HTML
<style>
.dataframe th, td:first-child {
background: #3f577c ;
font-family: monospace ;
color: white ;
border: 3px solid white ;
text-align: left !important ; }                                             
</style>

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO HTMLread_html, to_html, Styler.apply, Styler.applymap

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions