## Introduction Jupyter Notebooks are often used for data science and scientific computing such as machine learning as the interactive design allow you to experiment easily with your code. For our purpose, we will use Notebooks as it's a useful tool to learn how to code as well as writing reports. *Note on the difference between Notebook and Lab: Jupyter Notebook offers a simplified, lightweight notebook authoring experience, where as, JupyterLab offers a feature-rich, tabbed multi-notebook editing environment with additional tools like a customizable interface layout and system console* ## Setup and Installation Installing with Conda using CLI: - `conda install jupyter` Jupyter can also be installed using a Anaconda Navigator - Launching: - From terminal: `jupyter notebook` or `jupyter lab` - From Anaconda Navigator or VSCode - Navigating the interface: - Tabs and file browser - Kernel and terminals ## Notebook Basics - Creating a new notebook (`.ipynb`) - Types of cells: - Code - Markdown - Raw - Running a cell: `Shift + Enter` - Adding/removing cells - Restarting the kernel - Saving and auto-checkpoints ## Writing and Running Code - Python syntax: - `print("Hello, world!")` - Variables and functions - Loops and conditionals - Importing libraries: - `import numpy as np` - `import pandas as pd` - `import matplotlib.pyplot as plt` ## Using Markdown - Headers: `#`, `##`, `###` - Bullet lists: `- item` - Numbered lists: `1. item` - Emphasis: _italic_, **bold**, `monospace` - LaTeX equations: - Inline: `$E = mc^2$` - Block: `$$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$` - Embedding links and images ## Interactive Widgets (optional) Install `ipywidgets` from your package manager ```python import ipywidgets as widgets widgets.IntSlider() ``` Example using interact: ```python 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