diff options
Diffstat (limited to 'tutorials/module_1/jupyter_lab_notebook.md')
| -rw-r--r-- | tutorials/module_1/jupyter_lab_notebook.md | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/tutorials/module_1/jupyter_lab_notebook.md b/tutorials/module_1/jupyter_lab_notebook.md index 14d9236..f9b3393 100644 --- a/tutorials/module_1/jupyter_lab_notebook.md +++ b/tutorials/module_1/jupyter_lab_notebook.md @@ -7,16 +7,9 @@ Jupyter Notebooks are often used for data science and scientific computing such ## Setup and Installation -Installing with Conda using CLI: -- `conda install jupyter` -Jupyter can also be installed using a Anaconda Navigator +Jupyter Notebooks can be installed either from the Anaconda Navigator home page or directly from your Conda terminal. - - Launching: - - From terminal: `jupyter notebook` or `jupyter lab` - - From Anaconda Navigator or VSCode - - Navigating the interface: - - Tabs and file browser - - Kernel and terminals +Terminal: `conda install conda-forge::jupyterlab` ## Notebook Basics - Creating a new notebook (`.ipynb`) @@ -29,6 +22,29 @@ Jupyter can also be installed using a Anaconda Navigator - Restarting the kernel - Saving and auto-checkpoints +Jupyter Notebooks are files which allows you to combine *Code* and *Markdown* cells in one single document. The code cells, allow you to interactively run python code and print and plot data in your document. If you wish to update or change data your code you can re-run the cell to update the output. The markdown cells allows you to write text, titles and insert images in your documentation using the markup language *Markdown*. + +To start a new notebook select `File > New > Notebook` or right click the file browser and select `New notebook`, this will prompt you to select a kernel (the Jupyter notebook "engine"). For now, just select the default Kernel 3. This will start a new fresh kernel for us to use. Next, it's recommended to rename the file. + +Now that we have a blank notebook we can start to add cells. Add a cell and change the type to Markdown. Add a title with the hash symbol (`#`). As shown below. + +```markdown +# Title here +``` +Press `Shift + Enter` to run the cell. You just entered created your first markdown cell. +Now let's do the same but instead select code as the cell type, we're going to add some python code to the document. +```python +x = 4 +y = 3 + +x**2+2*y +``` +Again, run the cell and see what happens. You should've gotten an output of `22`. You can now use the notebook as a calculator, but there is so much more we can do. + +The order of running code matters. Think of the code cells as code snippets. Every time you run a cell variable will be updated. This means that the current state of all variables, functions, and imports depends on the history of what cells have been executed and in what order. In other words, if you run a later cell before running an earlier one that defines a variable or function it needs, you will get an error. If you change a variable in one cell and rerun it, that new value immediately affects the results of any cells that use that variable afterward — but not any previously run results unless you rerun them too. Variables and imports persist in memory between cells, but only based on the current session state — if you restart the kernel, you lose all previous definitions unless you re-run the necessary cells. Therefore, let's press the `Restart the kernel` button on the top window.3 + +Because of this, it's best practice to; Run cells in order, restart the kernel and run all cells (`Kernel -> Restart & Run All`) to make sure everything works cleanly and predictably and lastly, initialize important variables or imports in early cells, so they are always defined before they are needed. + ## Writing and Running Code - Python syntax: - `print("Hello, world!")` @@ -65,29 +81,11 @@ from ipywidgets import interact interact(lambda x: x**2, x=5) ``` - -## Productivity Tips -Here are some keyboard shortcuts to improve your productivity when writing in notebooks. - -| Key | Action | -| --- | ------------------ | -| A | insert cell above | -| B | insert cell below | -| M | switch to Markdown | -| Y | switch to code | - Magic commands: -- `%timeit`, `%matplotlib inline`, `%%bash` -Splitting and merging cells -Auto-save behavior - ## Exporting and Sharing - - File > Download As: - - Notebook (`.ipynb`) - - HTML - - PDF (requires LaTeX) - - Markdown -- Notebooks can be saved and shared via the following services: - - GitHub - - nbviewer.org - - mybinder.org - - JupyterHub
\ No newline at end of file +By default, jupyter auto-saves your notebooks as you work. + +- File > Download As: + - Notebook (`.ipynb`) + - HTML + - PDF (requires LaTeX) + - Markdown |
