https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/ https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/ https://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/docs/source/examples/Notebook/Notebook%20Basics.ipynb notebook: an interactive environment where both the code, code comments, narrative text (paragraphs, figures, etc), and results are mixed and integrated together, where you can run code one block at a time and see results jupyter notebook: interactive, web based interface (runs in your browser), live code and visualization supports more than 40+ languages, a json script cell: code block two modes: edit mode and command mode. Edit mode is indicated by a green cell border and a prompt showing in the editor area: Jupyter cell with green border When a cell is in edit mode, you can type into the cell, like a normal text editor. Enter edit mode by pressing `Enter` or using the mouse to click on a cell's editor area. Command mode is indicated by a grey cell border with a blue left margin: Jupyter cell with blue & grey border When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. Most importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell actions efficiently. For example, if you are in command mode and press CNTRL-ENTER (or CNTRL-RETURN on a Mac), that runs the contents of the current cell. If the contents are Python code, then that code is run. Another type of cell is a markdown cell, which allows for the display and formatting of text. These cells can either be rendered or unrendered. When rendered, the cell's contents are displayed nicely formatted. When they are unrendered, you will see the raw text source of the cell. To render the selected cell with the mouse, click the button in the toolbar or the "Cell:Run" menu item. To unrender the selected cell, double click on the cell. Keyboard Navigation The modal user interface of the Jupyter Notebook has been optimized for efficient keyboard usage. This is made possible by having two different sets of keyboard shortcuts: one set that is active in edit mode and another in command mode. The most important keyboard shortcuts are Enter, which enters edit mode, and Esc, which enters command mode. In edit mode, most of the keyboard is dedicated to typing into the cell's editor. Thus, in edit mode there are relatively few shortcuts. In command mode, the entire keyboard is available for shortcuts, so there are many more. The Help->Keyboard Shortcuts dialog lists the available shortcuts. We recommend learning the command mode shortcuts in the following rough order: Basic navigation: enter, shift-enter, up/k, down/j Saving the notebook: s Change Cell types: y, m, 1-6, t Cell creation: a, b Cell editing: x, c, v, d, z Kernel operations: i, 0 (press twice) stop: Jupyter File --> Close and Halt (closing the browser window is not enough) keyboard shortcuts ------------------ CMD-SHIFT-P list shortcuts Esc will take you into command mode where you can navigate around your notebook with arrow keys. While in command mode: A to insert a new cell above the current cell, B to insert a new cell below. M to change the current cell to Markdown, Y to change it back to code D + D (press the key twice) to delete the current cell Enter will take you from command mode back into edit mode for the given cell. CNTRL-RETURN run selected cell (even on Mac) run py files ------------ If you execute a cell containing: %load filename.py the content of filename.py will be loaded in the next cell. You can edit and execute it as usual. To save the cell content back into a file add the cell-magic %%writefile filename.py at the beginning of the cell and run it. Beware that if a file with the same name already exists it will be silently overwritten. To write/save %%writefile myfile.py write/save cell contents into myfile.py (use -a to append). Another alias: %%file myfile.py To run %run myfile.py run myfile.py and output results in the current cell To load/import %load myfile.py load "import" myfile.py into the current cell For more magic and help %lsmagic list all the other cool cell magic commands. %COMMAND-NAME? for help on how to use a certain command. i.e. %run? %run: Execute python code %run can execute python code from .py files - this is well-documented behavior. Lesser known is the fact that it can also execute other jupyter notebooks, which can quite useful. Note that using %run is not the same as importing a python module. # this will execute and show the output from # all code cells of the specified notebook %run ./two-histograms.ipynb convert notebook file to py file -------------------------------- On the command line, you can use nbconvert: $ jupyter nbconvert --to script [YOUR_NOTEBOOK].ipynb f you want to convert all *.ipynb files from current directory to python script, you can run the command like this: jupyter nbconvert --to script *.ipynb jupyter nbconvert --to script /path/to/notebooks/*.ipynb Current directory ----------------- jupyter --config-dir on Mac, user root, .jupyter if there is no jupyter_notebook_config.py file in that directory, generate one by typing: jupyter notebook --generate-config Then edit the jupyter_notebook_config.py file. Make sure to uncomment the original line. ## The directory to use for notebooks and kernels. c.NotebookApp.notebook_dir = 'c:\\users\\rsignell\\documents\\github' ## The directory to use for notebooks and kernels. c.NotebookApp.notebook_dir = '/Users/davidgerbing/Dropbox/511Stuff/Python/notebooks' Execute Shell Commands ---------------------- It's easy to execute a shell command from inside your notebook. You can use this to check what datasets are in available in your working folder: !ls *.csv