In [1]:
# code cell
name = "Jonathan"
In [2]:
import numpy as np
# don't do:
# from numpy import *
In [3]:
max("a")
Out[3]:
In [4]:
np.max("a")
In [5]:
%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 [6]:
first = 1
In [7]:
second = 2
In [8]:
third = 3
In [ ]:
In [9]:
print("oops")
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 [12]:
sns.distplot(canadian_politics["Age"].dropna());
In [13]:
sns.set_context("poster", font_scale=1.3)
In [14]:
fig, ax = plt.subplots(figsize=(12, 8))
sns.distplot(canadian_politics["Age"].dropna())
fig.tight_layout()
In [ ]:
#gather
In [ ]:
# Province, Party, Average, Age, Heatmap
In [17]:
pivot_ui(canadian_politics)
Out[17]:
In [16]:
canadian_politics['Age-bin'] = pd.cut(canadian_politics['Age'], [x for x in range(10, 100, 5)])
In [19]:
pd.read_clipboard(sep='\t')
Out[19]:
In [1]:
import numpy as np
In [2]:
from numpy.random import choice, chisquare
In [3]:
np.random.chisquare()
In [4]:
# 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.
In [ ]:
In [ ]:
np.linspace(50, 150, num=100, endpoint=False)
In [ ]:
plt.plot(np.linspace(start, stop))
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [5]:
np.linspace?
In [6]:
?np.linspace
In [8]:
np.linspace??
In [9]:
!subl ~/miniconda3/envs/dspy3/lib/python3.6/site-packages/numpy/core/function_base.py
In [10]:
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 [15]:
# But first find and replace
def silly_function(xval):
"""Takes a value and returns the value."""
xval_sq = xval ** 2.0
1 + 15
xval_abs = np.sqrt(xval_sq)
return xval_abs
In [16]:
silly_function(-2,)
Out[16]:
In [17]:
silly_function?
In [18]:
silly_function??
In [19]:
!ls ../data/
In [ ]:
coal_years = !ls ../data/coal_prod_20*.csv
In [ ]:
coal_years
In [21]:
ex_dictionary = {}
# Indent/dedent/comment
for index in range(5):
ex_dictionary["integer_one"] = 1
ex_dictionary["integer_two"] = 2
ex_dictionary["integer_three"] = 3
ex_dictionary["integer_four"] = 4
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 [22]:
%%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 [23]:
%%python2
print "hi"
In [ ]:
%%bash
wget http://www.ast.cam.ac.uk/~rfc/vpfit11.1.tar.gz
mkdir -p vpfit11
cd vpfit11
tar -xvzf ../vpfit11.1.tar.gz
In [24]:
normal_argument = 12.4
second_argument = 98.4
arg_with_spaces = "the secret to life"
In [25]:
%%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 [26]:
%%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 [ ]:
%env
In [ ]:
%env
In [ ]:
!pwd
In [27]:
a = 3
a
Out[27]:
In [28]:
2345 * 97543
Out[28]:
In [29]:
_
Out[29]:
In [30]:
_27
Out[30]:
In [31]:
print(_i27)
In [ ]:
In [34]:
saved = _27
In [35]:
saved
Out[35]:
In [ ]:
_
In [ ]:
_i55
In [36]:
%history -f alex.ipynb
Check out gather (microsoft)
In [ ]: