Skip to content

Instantly share code, notes, and snippets.

@chrisRedwine
Last active May 17, 2023 11:32
Show Gist options
  • Save chrisRedwine/356eb109e98b6caa8acd0296ccedc423 to your computer and use it in GitHub Desktop.
Save chrisRedwine/356eb109e98b6caa8acd0296ccedc423 to your computer and use it in GitHub Desktop.
Pandas CSS for Jupyter Notebooks
body {
margin: 0;
font-family: Helvetica;
}
table.dataframe {
border-collapse: collapse;
border: none;
}
table.dataframe tr {
border: none;
}
table.dataframe td, table.dataframe th {
margin: 0;
border: 1px solid white;
padding-left: 0.25em;
padding-right: 0.25em;
}
table.dataframe th:not(:empty) {
background-color: #fec;
text-align: left;
font-weight: normal;
}
table.dataframe tr:nth-child(2) th:empty {
border-left: none;
border-right: 1px dashed #888;
}
table.dataframe td {
border: 2px solid #ccf;
background-color: #f4f4ff;
}
%matplotlib inline
%load_ext autoreload
# always reload modules marked with "%aimport"
%autoreload 1
import os
import sys
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import HTML
root_dir = os.path.dirname(os.path.dirname(os.getcwd()))
notebooks_dir = os.path.join(root_dir, 'notebooks')
src_dir = os.path.join(root_dir, 'src')
data_dir = os.path.join(root_dir, 'data')
sql_path = os.path.join(data_dir, 'sql')
# add the 'src' directory as one where we can import modules
sys.path.append(src_dir)
LARGE_FIGSIZE = (12, 8)
# apply nice styling to pandas dataframes
pd.set_option("display.max_rows", 16)
pd.set_option('display.float_format', lambda x: '{:.2f}'.format(x))
with open(os.path.join(notebooks_dir, 'resources', 'pd.css'), 'r') as f:
HTML('<style>{}</style>'.format(f.read()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment