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 [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
%config InlineBackend.figure_format='retina'
# Add this to python2 code to make life easier
from __future__ import absolute_import, division, print_function
from itertools import combinations
import string
from IPython.display import IFrame, HTML, YouTubeVideo
import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib.pyplot import GridSpec
import seaborn as sns
import mpld3
import numpy as np
import pandas as pd
import os, sys
import warnings
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 [2]:
YouTubeVideo("ZbrRrXiWBKc", width=400, height=300)
Out[2]:
In [3]:
!conda install pivottablejs -y
In [4]:
df = pd.read_csv("../data/mps.csv", encoding="ISO-8859-1")
In [5]:
df.head(10)
Out[5]:
In [6]:
from pivottablejs import pivot_ui
In [7]:
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
In [10]:
second = 2
In [11]:
third = 3
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
SELECT *
FROM tablename
In [12]:
%%bash
pwd
for i in *.ipynb
do
wc $i
done
echo
echo "break"
echo
du -h *ipynb
In [13]:
def silly_absolute_value_function(xval):
"""Takes a value and returns the value."""
xval_sq = xval ** 2.0
xval_abs = np.sqrt(xval_sq)
return xval_abs
In [14]:
silly_absolute_value_function?
In [15]:
silly_absolute_value_function??
In [ ]:
# shift-tab
silly_absolute_value_function()
In [ ]:
# shift-tab-tab
silly_absolute_value_function()
In [ ]:
# shift-tab-tab-tab
silly_absolute_value_function()
In [5]:
import numpy as np
In [14]:
np.sin??
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [2]:
import numpy as np
In [3]:
# !conda install -c r rpy2 -y
In [4]:
import rpy2
In [ ]:
%load_ext rpy2.ipython
In [24]:
X = np.array([0,1,2,3,4])
Y = np.array([3,5,4,6,7])
In [17]:
%%R?
In [28]:
%%R -i X,Y -o XYcoef
XYlm = lm(Y~X)
XYcoef = coef(XYlm)
print(summary(XYlm))
par(mfrow=c(2,2))
plot(XYlm)
In [29]:
XYcoef
Out[29]:
In [ ]: