Jupyter Features CheatSheet

Shell Commands

You can execute Shell commands with the prefix !


In [36]:
!ls -la
!pwd


total 364
drwxrwxr-x 4 zas zas   4096 Dez 29 14:20  .
drwxrwxr-x 7 zas zas   4096 Dez 29 14:06  ..
drwxrwxr-x 4 zas zas   4096 Dez 27 22:00  dashboard_widgets
drwxrwxr-x 2 zas zas   4096 Dez 29 14:06  .ipynb_checkpoints
-rw-rw-r-- 1 zas zas 136847 Dez 29 12:56  IPyWidgets.ipynb
-rw-rw-r-- 1 zas zas 191765 Dez 29 14:20 'Jupyter Debug.ipynb'
/home/zas/Dropbox/Programming/ipython/00_Admin/Features

In [37]:
!pip install numpy
!pip list | grep pandas


Requirement already satisfied: numpy in /home/zas/anaconda3/lib/python3.6/site-packages (1.14.3)
pandas                             0.23.0   

Magic Commands

List all Magics


In [9]:
%lsmagic


Out[9]:
Available line magics:
%alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cat  %cd  %clear  %colors  %config  %connect_info  %cp  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

Avaliable line Magics

%alias
%alias_magic
%autocall
%automagic
%autosave
%bookmark
%cat
%cd
%clear
%colors
%config
%connect_info
%cp
%debug
%dhist
%dirs
%doctest_mode
%ed
%edit
%env            # %env: Set Environment Variables
%gui
%hist
%history
%killbgscripts
%ldir
%less
%lf
%lk
%ll
%load
%load_ext
%loadpy
%logoff
%logon
%logstart
%logstate
%logstop
%ls
%lsmagic
%lx
%macro
%magic
%man
%matplotlib
%mkdir
%more
%mv
%notebook
%page
%pastebin
%pdb
%pdef
%pdoc
%pfile
%pinfo
%pinfo2
%popd
%pprint
%precision
%profile
%prun
%psearch
%psource
%pushd
%pwd
%pycat
%pylab
%qtconsole
%quickref
%recall
%rehashx
%reload_ext
%rep
%rerun
%reset
%reset_selective
%rm
%rmdir
%run
%save
%sc
%set_env
%store
%sx
%system
%tb
%time        # time code execution
%timeit      # time code execution
%unalias
%unload_ext
%who
%who_ls
%whos
%xdel
%xmode

%env


In [16]:
# lists all environment variables
%env
# Set environment variable NUM_THREADS
%env NUM_THREADS=4


env: NUM_THREADS=4

%run


In [25]:
# %run: Execute python code
# Run another nothebook entirely
%run ../sample_files/hello_world.ipynb


hello_world

%load


In [26]:
# loads content of a file into the cell
# %load ../sample_files/hello_world.py
if __name__ == "__main__":
  print("Hello World!")

%time & timesit


In [31]:
# %time will give you information about a single run of the code in your cell.
%time
import time
for _ in range(1000):
  time.sleep(0.01)# sleep for 0.01 seconds


CPU times: user 4 µs, sys: 0 ns, total: 4 µs
Wall time: 7.87 µs

In [29]:
# %timeit uses the Python timeit module which runs a statement 100,000 times (by default) and then provides the mean of the fastest three times.
import numpy
%timeit numpy.random.normal(size=100)


7.82 µs ± 191 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

Highres Output


In [35]:
%matplotlib inline
import matplotlib.pyplot as plt
x = range(1000)
y = [i ** 2 for i in x]
plt.plot(x,y)
plt.show();

%config InlineBackend.figure_format = 'retina'
plt.plot(x,y)
plt.show();


Available Cell Magics


In [ ]:
%%!
%%HTML
%%SVG
%%bash
%%capture
%%debug
%%file
%%html
%%javascript
%%js
%%latex
%%perl
%%prun
%%pypy
%%python
%%python2
%%python3
%%ruby
%%script
%%sh
%%svg
%%sx
%%system
%%time
%%timeit
%%writefile

In [4]:
from IPython.display import Image
Image(filename='../sample_files/xkcd_estimation.png')


Out[4]:

In [41]:
from IPython.display import Image
Image(url='http://python.org/images/python-logo.gif')


Out[41]:

In [43]:
from IPython.display import YouTubeVideo
YouTubeVideo('1j_HxD4iLn8')


Out[43]:

In [47]:
import antigravity