In this post
Installation
By using pip,
pip install --upgrade pip # first, always upgrade pip!
pip install --upgrade ipython jupyter
By using conda,
conda install ipython jupyter
Or read more in this note.
Hotkeys / Shortcuts
There are 2 modes: command mode (pres ESC to activate) and edit mode (Enter to activate). Below are the most useful ones (for me).
You can edit / add more shortcuts in Help > Edit Keyboard Shortcuts.
Install new python package inside Jupyter Notebook
Using conda
[ref],
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} numpy
# DON'T DO THIS
!conda install --yes numpy
Using pip
,
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
# DON'T DO THIS
!pip install numpy
Display dataframes side-by-side
from IPython.display import display_html
def display_side_by_side(*args):
html_str=''
for df in args:
html_str+=df.to_html()
display_html(html_str.replace('table','table style="display:inline"'),raw=True)
display_side_by_side(df1,df2,df1)
Get previous outputs
_ # previous output
__ # second-to-last output
___ # third-to-last output
Display 2 figures side-by-side markdown cell
Put below codes in the markdown cell of Jupyter Notebook.
<tr>
<td> <img src="Nordic_trails.jpg" alt="Drawing" style="width: 250px;"/> </td>
<td> <img src="Nordic_trails.jpg" alt="Drawing" style="width: 250px;"/> </td>
</tr>
Check the info
Check the info of a function (gives us the documentation):
?<func-name>
Check the shortcodes of a function:
??<func-name>
Check where command executed from (in your $path
)?
!type python
python is /Users/thi/anaconda/envs/python3.6/bin/python
Magic Functions
- Check the full list (in examples) here or their docs here.
- You can define your custom magic functions here.
Auto update the new updated modules (put at the beginning of the notebook)
%load_ext autoreload
%autoreload 2
Check more settings of %autoreload
here.
Show the plots inside the notebook:
%matplotlib inline
Get the commands from 1 to 4:
%history -n 1-4 # get commands 1 to 4