Skip to content

CSS selector for index cells #28204

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

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

CSS selector for index cells #28204

kelmouloudi opened this issue Aug 28, 2019 · 4 comments · Fixed by #28216
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Milestone

Comments

@kelmouloudi
Copy link

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
Copy link
Contributor

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

@kelmouloudi
Copy link
Author

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

@simonjayhawkins
Copy link
Member

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

@simonjayhawkins simonjayhawkins added Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Aug 29, 2019
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Aug 29, 2019
@kelmouloudi
Copy link
Author

Great! Thank you!

TomAugspurger pushed 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
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
proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this issue Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants