Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS selector for index cells #28204

Closed
kelmouloudi opened this issue Aug 28, 2019 · 4 comments · Fixed by #28216
Labels
Milestone

Comments

@kelmouloudi
Copy link

@kelmouloudi kelmouloudi commented Aug 28, 2019

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?

@TomAugspurger

This comment has been minimized.

Copy link
Contributor

@TomAugspurger TomAugspurger commented Aug 28, 2019

Can you go through the history and see when / why it was changed?

@kelmouloudi

This comment has been minimized.

Copy link
Author

@kelmouloudi kelmouloudi commented Aug 28, 2019

I went through all the changelogs from 0.21 to 0.25.1 but didn't find any mention of it.

@simonjayhawkins

This comment has been minimized.

Copy link
Member

@simonjayhawkins simonjayhawkins commented Aug 29, 2019

I can confirm that the behaviour for repr_html is incorrect. I think this is due to the default for bold_rows being False for DataFrameFormatter while the default being True for to_html.

will do some tests tomorrow but may be caused by #27991

@kelmouloudi

This comment has been minimized.

Copy link
Author

@kelmouloudi kelmouloudi commented Aug 29, 2019

Great! Thank you!

TomAugspurger added a commit that referenced this issue Aug 30, 2019
* REGR: <th> tags for notebook display closes #28204
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this issue Aug 30, 2019
WillAyd added a commit that referenced this issue Aug 30, 2019
MarcoGorelli pushed a commit to MarcoGorelli/pandas that referenced this issue Sep 3, 2019
@jorisvandenbossche jorisvandenbossche added this to the 0.25.2 milestone Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.