Skip to content

Instantly share code, notes, and snippets.

@sdelquin
Last active May 17, 2023 11:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdelquin/ed7df0d5416a14726d1a6ed6cde09db2 to your computer and use it in GitHub Desktop.
Save sdelquin/ed7df0d5416a14726d1a6ed6cde09db2 to your computer and use it in GitHub Desktop.
Styles for Pandas Dataframes inspired in Kaggle formatting
/* Styles for Pandas Dataframes inspired in Kaggle formatting.
It works on JupyterLab and Jupyter Notebook */
:is(.jp-RenderedHTML, .rendered_html) table {
background: #fff;
border: 0;
border-right: 1px solid hsla(210, 3%, 87%, 0.5);
color: rgba(0, 0, 0, 0.7);
display: block;
font-size: 12px;
font-variant-numeric: tabular-nums;
margin: 16px 0 24px;
overflow: auto;
}
:is(.jp-RenderedHTML, .rendered_html) table td,
:is(.jp-RenderedHTML, .rendered_html) table th {
padding: 4px 8px;
vertical-align: middle;
}
:is(.jp-RenderedHTML, .rendered_html) table td:not([align="right"]),
:is(.jp-RenderedHTML, .rendered_html) table th:not([align="right"]) {
text-align: left;
}
:is(.jp-RenderedHTML, .rendered_html) table th {
background: hsla(210, 3%, 87%, 0.3);
border: 1px solid hsla(210, 3%, 87%, 0.8);
font-weight: 400;
}
:is(.jp-RenderedHTML, .rendered_html) table td {
border: 1px solid hsla(210, 3%, 87%, 0.5);
}
:is(.jp-RenderedHTML, .rendered_html) table tr,
:is(.jp-RenderedHTML, .rendered_html) table tr:nth-child(odd):not(:hover) {
background: #fff;
}
:is(.jp-RenderedHTML, .rendered_html) table + p {
color: rgba(0, 0, 0, 0.4);
margin-top: -16px;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(even):not(:hover) {
background: content-box;
}
@sdelquin
Copy link
Author

sdelquin commented Sep 14, 2021

Style example:
image

Load it from url:

# Custom style for DataFrames
from IPython.display import HTML
from urllib.request import urlopen
css = urlopen('https://bit.ly/3nrfqhx').read().decode('utf-8')
HTML(f'<style>{css}</style>')

Load it from local file:

# Custom style for DataFrames
from IPython.display import HTML
from pathlib import Path
css = Path('df-kaggle-style.css').read_text()
HTML(f'<style>{css}</style>')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment