10 lutego 2019

Styl tabeli w Jupyter Notebook

Domyślny wygląd tabeli generowanej przez Jupiter Notebook, możemy łatwo go zmienić.

Domyślny wygląd:

Jupyter Notebook styl tabeli

Kod

from IPython.display import HTML, display
from libs import Helpers

display(Helpers.set_css_style('./css/style.css'))

import seaborn as sns
iris = sns.load_dataset('iris')
iris.head(10)
def set_css_style(css_file_path):
    from IPython.display import HTML
    styles = open(css_file_path, "r").read()
    return HTML("<style>" + styles + "</style>")
.rendered_html table, .rendered_html th, .rendered_html tr, .rendered_html td {
  border: 1px  #c0c5ce solid;
}

.rendered_html table  thead  th {
  border-bottom: 1px solid black;
  background-color: cornsilk;
}

.rendered_html table  thead  th:first-child {
  border-right: 1px solid black;
}

.rendered_html table  tbody  th {
  border-right: 1px solid black;
  background-color: antiquewhite;
}

Wygląd po drobnej zmianie:

Jupyter Notebook styl tabeli

Repozytorium kodu

Kod źródłowy znajduje się w repozytorium GitHub (opens new window).