How to use a jupyter notebook
Table of contents
- The Jupyter Notebook Dashboard
- Creating a New Notebook
- Working with Cells
- Saving and Exporting Notebooks
- Shutting Down Jupyter Notebook
- Working with Cells in Jupyter Notebook
- Use Cases for Jupyter Notebook
- Ressources
The Jupyter Notebook Dashboard
The Jupyter Notebook dashboard is a web-based interface that allows you to manage your notebooks and files. From the dashboard, you can:
- Create new notebooks.
- Open existing notebooks by clicking on their names.
- Manage and organize files and folders.
- Access running notebooks and terminals.
- Shut down the Jupyter Notebook server when you’re done.
Creating a New Notebook
To create a new Jupyter Notebook, follow these steps:
-
From the Dashboard: Click on the “New” button in the top-right corner of the dashboard.
-
Choose a Kernel: You’ll be prompted to select a kernel. A kernel is an execution environment associated with a specific programming language (e.g., Python, R, Julia). Choose the appropriate kernel for your task (usually, you’ll use the default Python kernel).
-
Start Writing Code: You’ll be taken to a new notebook with an empty cell. You can start writing code in this cell.
Working with Cells
Jupyter Notebooks are organized into cells. There are two primary types of cells:
-
Code Cells: You can write and execute code in these cells. To run the code in a cell, press
Shift + Enter
. -
Markdown Cells: You can write text, explanations, and documentation in these cells using Markdown syntax. To render Markdown, press
Shift + Enter
.
Saving and Exporting Notebooks
To save your work in a Jupyter Notebook, click the floppy disk icon (or use Ctrl + S
or Cmd + S
on Mac). You can also export your notebook to various formats, including HTML, PDF, and more, by going to the “File” menu and selecting “Download as.”
Shutting Down Jupyter Notebook
When you’re done working with Jupyter Notebook, it’s essential to shut down the server properly to save your work and release resources:
-
Close All Notebooks: Make sure you’ve saved and closed all your notebooks.
-
Return to the Dashboard: If you’re in a notebook, click the “Jupyter” logo in the top-left corner to return to the dashboard.
-
Shut Down the Server: In the dashboard, go to the “File” menu and select “Quit.” Confirm that you want to shut down the server.
-
Terminate Terminal: In the terminal or command prompt where you started Jupyter Notebook, press
Ctrl + C
to stop the server. Confirm the shutdown if prompted.
Congratulations! You’ve now learned how to launch, create, and work with Jupyter Notebooks. This versatile tool will be invaluable as you engage in data analysis, coding, and documentation in your projects.
In the next sections, we’ll explore more advanced features and tips for using Jupyter Notebook effectively.
Working with Cells in Jupyter Notebook
Jupyter Notebook is built around the concept of cells, which are individual units of content that can contain code, text, or visualizations. Understanding how to work with cells is essential for effectively using Jupyter Notebook for your data analysis and coding tasks.
Cell Types
There are two primary types of cells in Jupyter Notebook:
-
Code Cells: These cells are used for writing and executing code. You can write Python (or other supported languages) code in these cells and execute it to see the results.
-
Markdown Cells: These cells are used for adding formatted text, explanations, and documentation using Markdown syntax. You can use Markdown cells to provide context, instructions, or commentary in your notebook.See MARKDOWN
Creating and Managing Cells
Here are some common operations for working with cells:
Creating a New Cell
- To create a new cell, select an existing cell and click the
+
button in the toolbar above or use the keyboard shortcuts:A
: Create a new cell above the selected cell.B
: Create a new cell below the selected cell.
Changing Cell Types
- To change the cell type, select the cell and go to the toolbar. Use the dropdown menu to switch between “Code” and “Markdown.”
Executing Code Cells
- To run the code in a code cell, select the cell and press
Shift + Enter
. The output will be displayed below the cell.
Editing and Deleting Cells
- To edit the content of a cell, simply double-click on it, and you can start typing or making changes.
- To delete a cell, select it and press
D
twice (i.e., pressD
key two times in succession).
Copying and Pasting Cells
- To copy a cell, select it and press
C
. - To paste a copied cell above the selected cell, press
V
for paste above orShift + V
for paste below.
Moving Cells
- To move a cell up or down, select it and press
M
to enter command mode. Then use theK
key to move it up or theJ
key to move it down.
Splitting and Merging Cells
-
To split a cell into multiple cells at a specific location, place your cursor where you want to split and press
Ctrl + Shift + Minus (-)
. -
To merge multiple cells, select them and click the “Merge” button in the toolbar or use the
Shift + M
shortcut.
Use Cases for Jupyter Notebook
Jupyter Notebook is a versatile and powerful tool used across various domains for interactive computing and data analysis. Its flexibility and support for multiple programming languages make it suitable for a wide range of use cases. Below are some common and notable use cases for Jupyter Notebook:
Data Analysis and Exploration
-
Data Cleaning: Jupyter Notebook is widely used for data preprocessing tasks, including data cleaning, transformation, and manipulation using libraries like Pandas.
-
Data Visualization: Matplotlib, Seaborn, and Plotly are commonly used in Jupyter Notebook to create interactive visualizations and explore datasets visually.
-
Statistical Analysis: Perform statistical analysis, hypothesis testing, and descriptive statistics to gain insights from data.
Machine Learning and AI Development
-
Model Development: Build, train, and evaluate machine learning and deep learning models using libraries such as Scikit-Learn and TensorFlow.
-
Hyperparameter Tuning: Experiment with different hyperparameter settings and model architectures interactively.
-
Model Interpretability: Visualize and interpret model predictions and feature importances.
Scientific Computing
-
Scientific Research: Conduct scientific research, simulate experiments, and analyze results using libraries like NumPy and SciPy.
-
Symbolic Mathematics: Use SymPy to perform symbolic mathematics and solve equations.
Education and Learning
-
Teaching: Instructors use Jupyter Notebook to teach programming, data science, and various subjects, providing interactive learning experiences.
-
Learning: Students can practice coding, experiment with concepts, and visualize data while learning.
Documentation and Reports
-
Interactive Reports: Create interactive and dynamic reports that combine code, text, visualizations, and explanations.
-
Reproducible Research: Facilitate reproducible research by documenting data analysis steps alongside code.
Data Science Prototyping
-
Proof of Concept: Quickly prototype data science projects to assess feasibility and gather initial insights.
-
Exploratory Data Analysis (EDA): Conduct thorough EDA to understand data distributions and patterns.
Collaboration and Sharing
-
Collaborative Work: Collaborate with colleagues by sharing Jupyter Notebooks for joint coding and analysis.
-
Sharing Insights: Share insights, findings, and results with stakeholders in an interactive format.
These are just a few examples of the diverse use cases for Jupyter Notebook. Its interactive and document-like interface, along with its extensive library ecosystem, makes it a valuable tool for professionals and learners across various fields. Whether you’re a data scientist, researcher, educator, or developer, Jupyter Notebook can enhance your productivity and enable creative exploration of data and code.
Ressources
Resources for Using Jupyter Notebook:
-
Jupyter Notebook Documentation: The official documentation with comprehensive guides and references.
-
DataCamp Jupyter Notebook Tutorial: A comprehensive tutorial on using Jupyter Notebook for data analysis.
-
Jupyter Notebook Tutorial - Corey Schafer: A YouTube video explaining the basics of Jupyter Notebook.
Interesting Notebooks to Explore:
-
GitHub Repository: A collection of notebooks covering many data science topics with Python.
-
Jupyter Gallery: A collection of interesting notebooks on various topics, including data visualization, machine learning, and more.
-
Matplotlib Gallery: Detailed examples of using the Matplotlib library for creating charts and visualizations.
-
Scikit-Learn Examples: Example notebooks demonstrating how to use the Scikit-Learn library for machine learning.
-
Deep Learning Notebooks: Companion notebooks to the book “Deep Learning for Coders with fastai and PyTorch” for deep learning.
-
Exploring Pandas: A series of data analysis notebooks using Pandas by Kevin Markham.
-
NLP with NLTK: Notebooks for machine learning in natural language processing using the NLTK library.