Jupyter Notebooks#
Welcome to jupyter notebooks, where you can easily combine text, equations, code and graphs all in one convenient place.
If you’ve installed this using the Anaconda distribution, congratulations! You already have most of the python modules you need.
What is a Jupyter Notebook?#
A Jupyter notebook is an interactive document that combines live code, visualizations, narrative text, and more. It’s widely used in data science, research, and education. Notebooks allow you to write and execute code in small, manageable cells.
Notebook Basics#
1. Cells#
Jupyter notebooks are composed of cells, which can contain code or text. You can add cells using the “Insert” menu or by using keyboard shortcuts.
2. Cell Types#
There are two main cell types:
Code Cells: For writing and executing code. You’ll use these to perform calculations and data analysis.
Markdown Cells: For writing text, explanations, and documentation. This cell you’re reading is a Markdown cell.
3. Running Cells#
To execute a code cell, select it and press Shift + Enter
. The output will appear below the cell. For instance, execute the code below:
2 + 3
Hopefully in the output (displayed just below the code cell) you should see the number 5!
4. Editing Cells#
To edit a cell, double-click on it (for code cells) or single-click (for Markdown cells).
5. Saving and Loading Notebooks#
To save your work, use Ctrl + S
or Cmd + S
. You can load existing notebooks by clicking “File” > “Open.”
Markdown Basics#
Markdown is a lightweight markup language for formatting plain text. You can use it to style your text in Markdown cells.
Create headings by using
#
(e.g.,## Heading 2
).Make text bold with
**double asterisks**
.Emphasize text with italics by using
*single asterisks*
.
Magic Commands#
Jupyter provides “magic commands” that extend the basic functionality.
%
-prefixed commands are line magics (run for a single line).%%
-prefixed commands are cell magics (run for the entire cell).
For example, %timeit
measures the execution time of a single line of code.
%timeit 3 + 2;
Keyboard Shortcuts#
Learn some useful keyboard shortcuts to improve your workflow. Access them via Help
> Keyboard Shortcuts
.
Conclusion#
You’ve covered the basics of Jupyter notebooks in this short tutorial. Remember, the best way to learn is by doing, so practice and explore the many features Jupyter has to offer. This is just the beginning of your journey into interactive computing and data analysis.
If you have any questions or want to explore further, there are plenty of online resources and tutorials available. Happy coding!