diff options
Diffstat (limited to 'book/module1/jupyter_lab_notebook.tex')
| -rw-r--r-- | book/module1/jupyter_lab_notebook.tex | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/book/module1/jupyter_lab_notebook.tex b/book/module1/jupyter_lab_notebook.tex new file mode 100644 index 0000000..9688bea --- /dev/null +++ b/book/module1/jupyter_lab_notebook.tex @@ -0,0 +1,160 @@ +\subsection{Introduction}\label{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. + +\emph{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} + +\subsection{Setup and Installation}\label{setup-and-installation} + +Installing with Conda using CLI: - \texttt{conda\ install\ jupyter} +Jupyter can also be installed using a Anaconda Navigator + +\begin{verbatim} +- Launching: + - From terminal: `jupyter notebook` or `jupyter lab` + - From Anaconda Navigator or VSCode +- Navigating the interface: + - Tabs and file browser + - Kernel and terminals +\end{verbatim} + +\subsection{Notebook Basics}\label{notebook-basics} + +\begin{itemize} +\tightlist +\item + Creating a new notebook (\texttt{.ipynb}) +\item + Types of cells: + + \begin{itemize} + \tightlist + \item + Code + \item + Markdown + \item + Raw + \end{itemize} +\item + Running a cell: \texttt{Shift\ +\ Enter} +\item + Adding/removing cells +\item + Restarting the kernel +\item + Saving and auto-checkpoints +\end{itemize} + +\subsection{Writing and Running Code}\label{writing-and-running-code} + +\begin{itemize} +\tightlist +\item + Python syntax: - \texttt{print("Hello,\ world!")} - Variables and + functions - Loops and conditionals +\item + Importing libraries: - \texttt{import\ numpy\ as\ np} - + \texttt{import\ pandas\ as\ pd} - + \texttt{import\ matplotlib.pyplot\ as\ plt} +\end{itemize} + +\subsection{Using Markdown}\label{using-markdown} + +\begin{itemize} +\tightlist +\item + Headers: \texttt{\#}, \texttt{\#\#}, \texttt{\#\#\#} +\item + Bullet lists: \texttt{-\ item} +\item + Numbered lists: \texttt{1.\ item} +\item + Emphasis: \emph{italic}, \textbf{bold}, \texttt{monospace} +\item + LaTeX equations: + + \begin{itemize} + \tightlist + \item + Inline: \texttt{\$E\ =\ mc\^{}2\$} + \item + Block: + \texttt{\$\$\textbackslash{}int\_0\^{}\textbackslash{}infty\ e\^{}\{-x\^{}2\}\ dx\ =\ \textbackslash{}frac\{\textbackslash{}sqrt\{\textbackslash{}pi\}\}\{2\}\$\$} + \end{itemize} +\item + Embedding links and images +\end{itemize} + +\subsection{Interactive Widgets +(optional)}\label{interactive-widgets-optional} + +Install \texttt{ipywidgets} from your package manager + +\begin{Shaded} +\begin{Highlighting}[] +\ImportTok{import}\NormalTok{ ipywidgets }\ImportTok{as}\NormalTok{ widgets} +\NormalTok{widgets.IntSlider()} +\end{Highlighting} +\end{Shaded} + +Example using interact: + +\begin{Shaded} +\begin{Highlighting}[] +\ImportTok{from}\NormalTok{ ipywidgets }\ImportTok{import}\NormalTok{ interact} +\NormalTok{interact(}\KeywordTok{lambda}\NormalTok{ x: x}\OperatorTok{**}\DecValTok{2}\NormalTok{, x}\OperatorTok{=}\DecValTok{5}\NormalTok{)} +\end{Highlighting} +\end{Shaded} + +\subsection{Productivity Tips}\label{productivity-tips} + +Here are some keyboard shortcuts to improve your productivity when +writing in notebooks. + +\begin{longtable}[]{@{}ll@{}} +\toprule\noalign{} +Key & Action \\ +\midrule\noalign{} +\endhead +\bottomrule\noalign{} +\endlastfoot +A & insert cell above \\ +B & insert cell below \\ +M & switch to Markdown \\ +Y & switch to code \\ +\end{longtable} + +Magic commands: - \texttt{\%timeit}, \texttt{\%matplotlib\ inline}, +\texttt{\%\%bash} Splitting and merging cells Auto-save behavior + +\subsection{Exporting and Sharing}\label{exporting-and-sharing} + +\begin{itemize} +\tightlist +\item + File \textgreater{} Download As: + + \begin{itemize} + \tightlist + \item + Notebook (\texttt{.ipynb}) + \item + HTML + \item + PDF (requires LaTeX) + \item + Markdown + \end{itemize} +\item + Notebooks can be saved and shared via the following services: - GitHub + - nbviewer.org - mybinder.org - JupyterHub +\end{itemize} |
