In [1]:
# code cell
name = "Jonathan"

In [2]:
# code cell
name = "Jonathan"

In [3]:
# code cell
name = "Jonathan"

In [4]:
# Add this to python2 code to make life easier -- safe to use in python3 as well.
from __future__ import absolute_import, division, print_function

In [5]:
import numpy as np
# don't do:
# from numpy import *

In [6]:
max('a')

In [7]:
np.max('a')

In [8]:
%matplotlib inline
%config InlineBackend.figure_format='retina'

In [9]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
from sklearn.datasets import load_boston
from pivottablejs import pivot_ui
import qgrid
import sys
import warnings
warnings.filterwarnings('ignore')

In [10]:
df = pd.read_csv("../data/mps.csv", encoding="ISO-8859-1")

In [11]:
# recommend using .head()
df.head(10)

In [12]:
# Province, Party, Average, Age, Heatmap

In [13]:
pivot_ui(df)

In [14]:
df_dict = load_boston()
features = pd.DataFrame(data=df_dict.data, columns = df_dict.feature_names)
target = pd.DataFrame(data=df_dict.target, columns = ['MEDV'])
df = pd.concat([features, target], axis=1)

In [15]:
df['Zone'] = df['ZN'].astype('category')
df['CHAS'] = df['CHAS'].astype('category')
df.head()

In [16]:
qgrid_widget = qgrid.show_grid(df[['CRIM',
                                   'Zone',
                                   'INDUS',
                                   'CHAS',
                                   'NOX',
                                   'AGE',
                                   'RAD',
                                   'LSTAT',
                                   'MEDV',
                                  ]], show_toolbar=True)

In [17]:
qgrid_widget

In [18]:
df2 = qgrid_widget.get_changed_df()

In [19]:
df2.head(7)

In [20]:
df.head(7)

In [21]:
import numpy as np

In [22]:
# shift-tab right ↓ more useful
np.linspace(start=50, endpoint=False, endpoint=100)

In [23]:
# shift-tab right ↓ more useful
np.linspace(start=50, endpoint=False, stop=100)

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 [28]:
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 [29]:
# But first find and replace
def silly_function(xval):
    """Takes a value and returns the value."""
    xval_sq = xval ** 2.0
    1 + 12
    xval_abs = np.sqrt(xval_sq)
    return xval_abs

In [30]:
silly_function?

In [31]:
silly_function??

In [32]:
silly_function??

In [33]:
# But first find and replace
def silly_function(xval):
    """Takes a value and returns the value."""
    xval_sq = xval ** 2.0
    1 + 10
    xval_abs = np.sqrt(xval_sq)
    return xval_abs

In [34]:
silly_function??

In [35]:
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 [36]:
!ls ../data/

In [37]:
coal_years = !ls ../data/coal_prod_20*.csv

In [38]:
coal_years

In [39]:
example_dict = {}

# Indent/dedent/comment
for index in range(5):
    example_dict["one"] = 1
    example_dict["two"] = 2
    example_dict["three"] = 3
    example_dict["four"] = 4

In [40]:
example_dict["prepend_one_better_neat"] = 1
example_dict["prepend_two_better_neat"] = 2
example_dict["prepend_three_better_neat"] = 3
example_dict["prepend_four_better_neat"] = 4

In [41]:
example_dict["one_better_neat"] = 1
example_dict["two_better_neat"] = 2
example_dict["three_better_neat"] = 3
example_dict["four_better_neat"] = 4

In [42]:
%%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 [43]:
%%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 [44]:
normal_argument = 12.4
second_argument = 98.4

arg_with_spaces = "the secret to life"

In [45]:
%%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 [46]:
%%bash -s "$arg_with_spaces"
echo "This bash script knows $1."

In [47]:
ls

In [48]:
!ls

In [49]:
%ls

In [50]:
tailthing = "*.ipynb"

In [51]:
!ls {tailthing}

In [52]:
output = !ls

In [53]:
output

In [54]:
%env

In [55]:
!pwd

In [56]:
a = 3
a

In [57]:
_i56

In [58]:
_56

In [59]:
_

In [60]:
b = 5
b * 15

In [61]:
_

In [62]:
c = a * b

In [63]:
%notebook history.ipynb

In [64]:
!subl 01-Tips-and-tricks.ipynb