Jupyter Notebook Preamble
jupyter
python
r
Whenever I use Jupyter Notebooks for analysis I tend to set a bunch of options at the top of every file to make them more pleasant to use. Here they are for Python and R with IRKernel
Python
# Automatically reload code from dependencies when running cells
# This is indispensible when importing code you are actively modifying.
%load_ext autoreload
%autoreload 2
# I almost always use pandas and numpy
import pandas as pd
import numpy as np
# Set the maximum rows to display in a dataframe
= 100
pd.options.display.max_rows # Set the maximum columns to display in a dataframe
= 200
pd.options.display.max_columns # Set the maximum width of columns to display in a dataframe
= 80
pd.options.display.max_colwidth # Don't render $..$ as TeX in a dataframe
= False pd.options.display.html.use_mathjax
R
For R I configure similar display options to Python through repr:
# Set the maximum number of columns and rows to display
options(repr.matrix.max.cols=150, repr.matrix.max.rows=200)
# Set the default plot size
options(repr.plot.width=18, repr.plot.height=12)
# Usual analysis libraries
suppressPackageStartupMessages({
library(tidyverse)
library(ggformula)
library(glue)
library(lubridate)
}
# Database Libraries
library(DBI)
library(dbplyr)