Jupyter Notebook

Page content

Environment

  • macOS: 10.15.3
  • Python: pyenv installed

Install

pip install -U pip
pip install jupyter

How to

Run

jupyter-notebook run the Jupyter.

% jupyter-notebook
[I 19:21:07.376 NotebookApp] Serving notebooks from local directory: /Users/atlex/nlp
[I 19:21:07.376 NotebookApp] The Jupyter Notebook is running at:
[I 19:21:07.376 NotebookApp] http://localhost:8888/?token=8637cf3f5b526b4ac33e93964844ecf7626ccd7be92616a2
[I 19:21:07.376 NotebookApp]  or http://127.0.0.1:8888/?token=8637cf3f5b526b4ac33e93964844ecf7626ccd7be92616a2
[I 19:21:07.376 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 19:21:07.381 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///Users/atlex/Library/Jupyter/runtime/nbserver-15083-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=8637cf3f5b526b4ac33e93964844ecf7626ccd7be92616a2
     or http://127.0.0.1:8888/?token=8637cf3f5b526b4ac33e93964844ecf7626ccd7be92616a2

The root directory showing on the browser is the directory where you run the command.

Make a project

In the web page, click New -> Notebook:Python 3. A new tab will open at the browser and you can write your Python code!

Short cuts (memo)

green - edit mode blue - command mode

commandmode + d*2 -> delete the cell (like a vim)
commandmode + a -> new cell above
commandmode + b -> new cell below

delete results

https://stackoverflow.com/questions/39924826/keyboard-shortcut-to-clear-cell-output-in-jupyter-notebook

Tips - Re-running all cells in above

https://stackoverflow.com/questions/32267540/ipython-jupyter-can-we-program-a-run-all-cell-above

from IPython.core.display import display, HTML
HTML('''<script> </script> <form action="javascript:IPython.notebook.execute_cells_above()"><input type="submit" id="toggleButton" value="Run all"></form>''')

Tips - pandas memo

At production in place

https://stackoverflow.com/questions/43893457/understanding-inplace-true

Dev can do without inplace it fast

Tips - ehck duplicate in liset

https://stackoverflow.com/questions/1541797/how-do-i-check-if-there-are-duplicates-in-a-flat-list

len(your_list) != len(set(your_list))

Tips - show current tokens

jupyter-notebook list