Pandas Tutorial

Creating Objects

Viewing Data

Selection

Manipulating Data

Grouping Data

Merging, Joining and Concatenating

Working with Date and Time

Working With Text Data

Working with CSV and Excel files

Operations

Visualization

Applications and Projects

How To Use Jupyter Notebook - An Ultimate Guide

Jupyter Notebook is a highly popular tool among data scientists and researchers for creating and sharing documents that contain live code, equations, visualizations, and narrative text. Let's go through a comprehensive guide on how to use Jupyter Notebook:

1. Installation

Using pip:

pip install jupyter

Using Anaconda:

It's often simpler to install Jupyter via Anaconda, especially for beginners. Once you have Anaconda installed, Jupyter comes bundled with it.

2. Launching Jupyter Notebook

In your terminal or command prompt, simply type:

jupyter notebook

This will launch Jupyter in your default browser.

3. Jupyter Dashboard

Once launched, you'll be in the Jupyter Dashboard:

  • Files: Shows a list of files and folders in the current directory.
  • Running: Displays currently running notebooks.
  • Clusters: (Deprecated in newer versions) Was used to manage multiple kernels.

To create a new notebook, click on the "New" button and select a kernel, typically "Python 3".

4. Basic Operations in Notebook

4.1 Cells

Jupyter operates with "cells". A cell can be code, markdown, or raw text.

Executing a cell: Press Shift + Enter or click on the "Run" button.

4.2 Modes

  • Edit Mode: Allows you to type code/text into a cell. Indicated by a green border. Enter this mode by pressing Enter or clicking on a cell.

  • Command Mode: Navigate around the notebook using keyboard shortcuts. Indicated by a blue border. Press Esc to enter this mode.

4.3 Shortcuts

  • Create a new cell above: a (in Command Mode)
  • Create a new cell below: b (in Command Mode)
  • Delete a cell: dd (in Command Mode)
  • Change cell type to Markdown: m (in Command Mode)
  • Change cell type to Code: y (in Command Mode)

5. Markdown & LaTeX

Jupyter supports Markdown for creating structured documents.

For example, # This is a header in a Markdown cell becomes a header.

Jupyter also supports LaTeX for mathematical equations. Wrap your equation with $ for inline and $$ for block:

  • Inline: $e^{i\pi} + 1 = 0$
  • Block: $$e^{i\pi} + 1 = 0$$

6. Magic Commands

These are special commands that provide useful features:

  • %run: Runs a python script.

  • %load: Inserts the code from an external script.

  • %timeit: Measures the execution time of the code in the current cell.

7. Plotting and Visualization

Jupyter has built-in support for displaying plots from libraries like Matplotlib. Just make sure to include the line %matplotlib inline at the top of your notebook to display plots within the notebook.

8. Extensions

Jupyter has a vast ecosystem of extensions. Some popular ones can be installed via the Jupyter-contrib extensions package:

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

9. Exporting & Converting

Jupyter notebooks can be exported in various formats like PDF, HTML, and Python scripts via the File -> Download as menu.

10. Shutting Down

Simply close the browser tab and go back to the terminal. Press Ctrl+C and confirm to shut down the Jupyter server.

Conclusion

Jupyter Notebook is a powerful tool, especially when combined with Python's data science stack: Pandas, Numpy, Scikit-learn, Matplotlib, etc. This guide provides the basics to get started, but there's much more to explore!

  1. Data visualization in Jupyter using Matplotlib and other libraries:

    import matplotlib.pyplot as plt
    %matplotlib inline
    
    # Create a simple plot
    x = [1, 2, 3, 4, 5]
    y = [2, 4, 6, 8, 10]
    plt.plot(x, y)
    plt.show()
    
  2. Interactive widgets and dashboards in Jupyter:

    from ipywidgets import interact
    
    # Create an interactive slider
    @interact(x=(0, 10))
    def square(x):
        print(f'Square of {x} is {x*x}')