Let's start with pep8 (https://www.python.org/dev/peps/pep-0008/)
Imports should be grouped in the following order:
- standard library imports
- related third party imports
- local application/library specific imports
You should put a blank line between each group of imports. Put any relevant all specification after the imports.
In [2]:
# Best practice for loading libraries?
# Couldn't find what to do with 'magic' imports at the top
%load_ext autoreload
%autoreload 2
%matplotlib inline
%config InlineBackend.figure_format='retina'
from __future__ import division
from itertools import combinations
import string
from IPython.display import IFrame, HTML, YouTubeVideo
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scipy as sp
import seaborn as sns; sns.set();
plt.rcParams['figure.figsize'] = (12, 8)
sns.set_style("darkgrid")
sns.set_context("poster", font_scale=1.3)
http://nicolas.kruchten.com/content/2015/09/jupyter_pivottablejs/
In [3]:
YouTubeVideo("ZbrRrXiWBKc", width=800, height=600)
Out[3]:
In [4]:
!pip install pivottablejs
In [5]:
df = pd.read_csv("../data/mps.csv")
In [6]:
df.head()
Out[6]:
In [7]:
from pivottablejs import pivot_ui
pivot_ui(df)
# Province, Party, Average, Age, Heatmap
Out[7]:
In [8]:
# in select mode, shift j/k (to select multiple cells at once)
# split cell with ctrl shift -
In [9]:
first = 1
second = 2
third = 3
In your documentation if you indent by 4 spaces, you get monospaced code-style code so you can embed in a Markdown cell:
$ mkdir toc
$ cd toc
$ wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.js
$ wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.css
$ cd ..
$ jupyter-nbextension install --user toc
$ jupyter-nbextension enable toc/toc
You can also get syntax highlighting if you tell it the language that you're including:
mkdir toc
cd toc
wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.js
wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.css
cd ..
jupyter-nbextension install --user toc
jupyter-nbextension enable toc/toc
In [10]:
import rpy2
In [11]:
%load_ext rpy2.ipython
In [12]:
X = np.array([0,1,2,3,4])
Y = np.array([3,5,4,6,7])
In [13]:
%%R -i X,Y -o XYcoef
XYlm = lm(Y~X)
XYcoef = coef(XYlm)
print(summary(XYlm))
par(mfrow=c(2,2))
plot(XYlm)
In [ ]: