In [4]:
    
# code cell
name = "Jonathan"
    
In [6]:
    
import numpy as np
# don't do:
# from numpy import *
    
In [7]:
    
max("a")
    
    Out[7]:
In [8]:
    
np.max("a")
    
    
In [9]:
    
# %matplotlib inline
# %config InlineBackend.figure_format='retina'
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
from pivottablejs import pivot_ui
import sys
import warnings
warnings.filterwarnings("ignore")
    
In [ ]:
    
first = 1
    
In [ ]:
    
second = 2
    
In [ ]:
    
third = 3
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
print("oops")
    
In [ ]:
    
    
In [ ]:
    
    
A library and example from: http://nicolas.kruchten.com/content/2015/09/jupyter_pivottablejs/
In [10]:
    
# df = pd.read_csv("../data/mps.csv", encoding="ISO-8859-1")
# canadian_politics = pd.read_csv("../data/montreal_2014.csv",)
canadian_politics = pd.read_csv("../data/mps2.csv")
    
In [11]:
    
# recommend using .head()
canadian_politics.head(10)
    
    Out[11]:
In [14]:
    
sns.distplot(canadian_politics["Age"].dropna());
    
    
In [15]:
    
sns.set_context("poster", font_scale=1.3)
    
In [16]:
    
fig, ax = plt.subplots(figsize=(12, 8))
sns.distplot(canadian_politics["Age"].dropna())
fig.tight_layout()
    
    
In [ ]:
    
# Province, Party, Average, Age, Heatmap
    
In [20]:
    
pivot_ui(canadian_politics)
    
    Out[20]:
In [22]:
    
canadian_politics['Age-bin'] = pd.cut(canadian_politics['Age'], [x for x in range(10, 100, 5)])
# pd.qcut(canadian_politics['Age'], [x for x in range(10, 100, 5)])
    
In [21]:
    
pd.read_clipboard(sep='\t')
    
    Out[21]:
In [23]:
    
import numpy as np
    
In [ ]:
    
from numpy.random import choice, chisquare
    
In [ ]:
    
np.random.chisquare()
    
In [ ]:
    
# pure tab right ↓ less useful
np.random.choice()
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
# shift-tab right ↓ more useful
np.linspace(start=50, stop=100, endpoint=False)
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
np.linspace()
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
np.linspace(50, 150, num=100, endpoint=False)
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
plt.plot(np.linspace(start, stop))
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [24]:
    
np.linspace?
    
In [25]:
    
?np.linspace
    
In [26]:
    
np.linspace??
    
In [27]:
    
!subl ~/miniconda3/envs/dspy3/lib/python3.6/site-packages/numpy/core/function_base.py
    
In [29]:
    
import textwrap
def example_function():
    """Docstring for example function"""
    
    print(textwrap.dedent("""
    This is a multi-lined string
    that I want to write inside of a function.
    Notice what happens when I print this.
        And when something is indented more."""))
example_function()
    
    
In [44]:
    
# But first find and replace
def silly_function(xval):
    """Takes a value and returns the value."""
    xval_sq = xval ** 2.0
    3 + 15
    xval_abs = np.sqrt(xval_sq)
    return xval_abs
    
In [45]:
    
silly_function(-2,)
    
    
In [37]:
    
silly_function?
    
In [38]:
    
silly_function??
    
In [39]:
    
!ls ../data/
    
    
In [40]:
    
coal_years = !ls ../data/coal_prod_20*.csv
    
In [41]:
    
coal_years
    
    Out[41]:
In [42]:
    
from glob import glob
    
In [43]:
    
for filename in glob("../data/coal_prod_20*.csv"):
    print(filename)
    
    
In [46]:
    
ex_dictionary22 = {}
# Indent/dedent/comment
for index in range(5):
    ex_dictionary22["integer_one"] = 1
    ex_dictionary22["integer_two"] = 2
    ex_dictionary22["integer_three"] = 3
    ex_dictionary22["integer_four"] = 4
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
In [ ]:
    
    
Hold down option, click and drag (for big cursor).
cmd + click == wherever you click.
Shift command P -- command palette Classic Notebook Shift command C -- command palette in JupyterLab
Hide left bar (CMD + B)
Full screen CMD + Shift + D (but CTRL + CMD F for browser fullscreen)
Move cells around mouse
In [ ]:
    
example["one_better_neat"] = 1
example["two_better_neat"] = 2
example["three_better_neat"] = 3
example["four_better_neat"] = 4
    
You can also get monospaced fonts by indenting 4 spaces:
mkdir toc
cd toc
Wrap with triple-backticks and language:
mkdir toc
cd toc
wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
SELECT first_name,
       last_name,
       year_of_birth
FROM presidents
WHERE year_of_birth > 1800;
In [47]:
    
%%latex
If you want to get crazier$\ldots$
\begin{equation}
\oint_S {E_n dA = \frac{1}{{\varepsilon _0 }}} Q_\textrm{inside}
\end{equation}
    
    
In [48]:
    
%%python2
print "hi"
    
    
In [49]:
    
%%bash
wget http://www.ast.cam.ac.uk/%7Erfc/vpfit12.2.tar.gz
mkdir -p vpfit12
cd vpfit12
tar -xvzf ../vpfit11.1.tar.gz
    
    
In [50]:
    
normal_argument = 12.4
second_argument = 98.4
arg_with_spaces = "the secret to life"
    
In [51]:
    
%%bash -s {normal_argument} {second_argument}
echo "This script knows the value of the argument: $1"
echo "It also has no trouble with the second argument: $2"
    
    
In [52]:
    
%%bash -s "$arg_with_spaces"
echo "This bash script knows $1."
    
    
In [ ]:
    
ls
    
In [ ]:
    
!ls
    
In [ ]:
    
ls vpfit10/
    
In [ ]:
    
tailthing = "*.ipynb"
    
In [ ]:
    
tailthing
    
In [ ]:
    
!ls {tailthing}
    
In [ ]:
    
output = !ls
    
In [ ]:
    
output
    
In [53]:
    
%env
    
    Out[53]:
In [ ]:
    
%env
    
In [54]:
    
!pwd
    
    
In [55]:
    
a = 3
a
    
    Out[55]:
In [56]:
    
2345 * 97543
    
    Out[56]:
In [57]:
    
_
    
    Out[57]:
In [58]:
    
_55
    
    Out[58]:
In [59]:
    
print(_i55)
    
    
In [ ]:
    
    
In [ ]:
    
saved = _27
    
In [ ]:
    
saved
    
In [ ]:
    
_
    
In [ ]:
    
_i55
    
In [ ]:
    
%history -f alex.ipynb
    
Check out gather (microsoft)
In [ ]: