getting_started_jupyter
Getting Started with JupyterLab/Notebook
Section titled “Getting Started with JupyterLab/Notebook”The most common way to interact with the IPython kernel is through a Jupyter web interface like JupyterLab or the classic Jupyter Notebook. Let’s see how to start and perform basic operations.
Starting JupyterLab
Section titled “Starting JupyterLab”Open your terminal or Anaconda Prompt, navigate to the directory where you want to store your notebooks, and type:
jupyter labThis command starts the JupyterLab server and should automatically open a new tab in your default web browser pointing to the JupyterLab interface (usually at http://localhost:8888/lab).
The JupyterLab interface typically shows a file browser on the left, a main work area in the center, and potentially other panes for running terminals, kernels, etc.
Starting the Classic Jupyter Notebook
Section titled “Starting the Classic Jupyter Notebook”If you prefer the classic interface, use:
jupyter notebookThis will open the classic Notebook dashboard in your browser, showing a file list from the directory where you started the command.
Creating a New Notebook
Section titled “Creating a New Notebook”In JupyterLab, use the ’+’ button in the file browser or the ‘Launcher’ tab to create a new notebook, typically selecting the ‘Python 3 (ipykernel)’ kernel.
In the classic Notebook dashboard, click the ‘New’ button and select ‘Python 3’.
This opens a new browser tab containing an empty notebook file (.ipynb).
The Notebook Interface: Cells
Section titled “The Notebook Interface: Cells”A notebook consists of cells. Cells are containers for code or text. The two primary cell types are:
- Code Cells: Contain code to be executed by the kernel (e.g., Python code). They have an
In [ ]:prompt. - Markdown Cells: Contain text formatted using Markdown syntax, allowing for rich text, headings, lists, links, images, and equations. They are used for documentation and narrative.
You can change the type of the currently selected cell using the dropdown menu in the toolbar or keyboard shortcuts (e.g., Esc to enter Command Mode, then m for Markdown or y for Code).
Executing Code
Section titled “Executing Code”To execute the code in a code cell:
- Select the cell.
- Press Shift + Enter (executes the cell and selects/creates the cell below).
- Press Ctrl + Enter (executes the cell and keeps it selected).
- Press Alt + Enter (executes the cell and inserts a new cell below).
When you execute a code cell:
- The code is sent to the IPython kernel.
- The kernel executes the code.
- Any output (from
printstatements, or the value of the last expression in the cell) is displayed below the cell. - The prompt number
In [ ]:changes toIn [*]:while running, and then toIn [N]:(where N is the execution count) upon completion.
# Example Code Cellimport timeprint("Starting calculation...")time.sleep(2)result = 10 + 5print("Calculation finished.")result # The value of the last expression is displayed as output
# Output after execution:# Starting calculation...# Calculation finished.# Out[N]: 15Markdown Cells
Section titled “Markdown Cells”Enter text using Markdown syntax in a Markdown cell. Execute the cell (Shift+Enter) to render it into formatted text.
# Example Markdown Cell (Raw Text)# My Analysis Plan
This notebook explores the dataset `data.csv`.
1. Load the data2. Perform initial cleaning3. Generate visualizations
See [Markdown Cheatsheet](https://www.markdownguide.org/cheat-sheet/) for syntax.
# Rendered Output after Shift+Enter:# (Formatted text with heading, list, and link)Saving Notebooks
Section titled “Saving Notebooks”Notebooks are saved automatically at intervals, but you can manually save using the floppy disk icon, Ctrl + S, or Cmd + S.
Stopping the Server
Section titled “Stopping the Server”To shut down the Jupyter server, go back to the terminal where you started jupyter lab or jupyter notebook and press Ctrl + C twice.
This covers the basics of launching Jupyter and working with notebook cells. The next sections will delve into specific IPython features available within this environment.