Built with Tutify.io

    AIStudyLabs

    Install Jupyter Notebooks

    Install Jupyter Notebooks

    Getting Started with Jupyter Notebooks

    The interactive shell is great for very small experiments. For anything more structured—data analysis, step-by-step tutorials, or experiments you want to save—Jupyter Notebooks are ideal.

    Installing Jupyter and JupyterLab

    To use Jupyter Notebooks, you'll first need to install Jupyter. If you're using Python, you can install them via pip. Run the following command in your terminal or command prompt:

    pip install jupyter 
    

    This will install Jupyter Notebook .

    Alternatively, you can also install jupyterlab

    pip install jupyterlab
    

    Launching Jupyter and Creating a Notebook

    From a terminal in your working directory, run:

    jupyter notebook
    

    This will open a web interface in your default browser (usually at http://localhost:8888). In the browser:

    1. Navigate to the folder where you want your notebook.
    2. Click New → Python 3 (ipykernel) (or similar).
    3. A new notebook opens with an empty code cell.

    Save your notebook with a descriptive name, e.g., intro_shell_and_notebooks.ipynb.


    Working with Code Cells in Jupyter

    A notebook consists of cells. The most common type is the code cell, where you write and run Python code.

    Writing and Running Code Cells

    Click in the first cell and write:

    message = "Hello from Jupyter!"
    message
    

    Run the cell with Shift + Enter (or the Run button in the toolbar).

    # Output
    'Hello from Jupyter!'
    

    Explanation: Jupyter displays the last expression’s result in a cell. Assignments (message = ...) don’t produce visible output unless explicitly printed or returned as the last expression.

    Example: Simple Data Analysis in a Notebook Cell

    prices = [19.99, 5.49, 3.5, 12.0]
    
    # Compute basic stats
    count = len(prices)
    minimum = min(prices)
    maximum = max(prices)
    average = sum(prices) / count
    
    count, minimum, maximum, round(average, 2)
    
    # Output
    (4, 3.5, 19.99, 10.25)
    

    Explanation:

    Re-running and Editing Cells

    One of Jupyter’s strengths is iterative development:

    1. Modify the code in an existing cell.
    2. Re-run it (Shift + Enter).
    3. Any variables defined or changed apply to later cells.

    For example, if you add a new price:

    prices.append(7.25)
    len(prices), max(prices)
    
    # Output
    (5, 19.99)
    

    Explanation: The notebook remembers prices from previous cells. You can build logic step-by-step across multiple cells.


    Using Markdown Cells for Documentation

    To make notebooks readable and shareable, combine code with Markdown cells for text, explanations, and results.

    Creating and Editing Markdown Cells

    1. Insert a new cell (using the + button or B/A in command mode).
    2. Change its type to Markdown (drop-down menu or press M in command mode).
    3. Write Markdown text, then run the cell (Shift + Enter) to render it.

    Example: Markdown for Section Headings and Explanations

    In a Markdown cell, you might write:

    # Sales Analysis
    
    In this section, we analyze basic statistics of product prices.
    
    - **Count**: number of items
    - **Min/Max**: price range
    - **Average**: typical price level
    

    Rendered, this becomes a nicely formatted heading with a bullet list.

    Combining Code and Markdown for a Reproducible Workflow

    1. A Markdown cell describes what the next code does.
    2. A code cell implements the logic.
    3. Another Markdown cell summarizes or interprets the result.

    Example: Documented Computation

    Markdown cell:

    ### Discounted Prices
    
    Apply a 10% discount to each price and compute the new average.
    

    Code cell:

    discounted = [round(p * 0.9, 2) for p in prices]
    original_avg = round(sum(prices) / len(prices), 2)
    new_avg = round(sum(discounted) / len(discounted), 2)
    
    original_avg, new_avg
    
    # Output
    (10.25, 9.23)
    

    Explanation: The list comprehension applies a 10% discount. The original and new averages are shown so that the Markdown commentary can interpret the impact.

    Summary / Key Takeaways

    In this lesson Using the Interactive Shell and Jupyter Notebooks, you have learned:

    Python Beginner Tutorial with Examples — Getting Started with Python and the Course

    Getting Started with Python and the Course

    Python Basics

    Control Flow in Python

    Data Structures in Python

    Functions and Scope in Python

    Error Handling and Debugging

    Working with Libraries

    Script Writing and Automation

    Real-world Applications of Python

    Advanced Python Concepts

    Best Practices in Python

    Tutorial Not Found