close icon
daily.dev platform

Discover more from daily.dev

Personalized news feed, dev communities and search, much better than what’s out there. Maybe ;)

Start reading - Free forever
Start reading - Free forever
Continue reading >

Jupyter for Beginners

Jupyter for Beginners
Author
Nimrod Kramer
Related tags on daily.dev
toc
Table of contents
arrow-down

🎯

A comprehensive guide for beginners to start using Jupyter Notebook for data science and programming. Learn how to install, launch, and create your first notebook. Explore the interface, keyboard shortcuts, Markdown basics, saving and shari

Jupyter Notebook is a versatile, free tool perfect for beginners entering the world of data science and programming. It supports over 40 programming languages and combines live code, equations, visualizations, and text in a single document. Here's a quick guide to get you started:

  • Introduction to Jupyter: Learn what Jupyter Notebook is and why it's beneficial for data science projects.

  • Prerequisites: Basic understanding of Python, pandas, and NumPy.

  • Installation Guide: How to set up Jupyter using Anaconda or pip.

  • Launching Jupyter Notebook: Simple steps to start your first notebook.

  • Creating Your First Notebook: Dive into writing and running code.

  • Understanding the Notebook Interface: Familiarize yourself with code cells, Markdown cells, and kernels.

  • Keyboard Shortcuts: Speed up your workflow with these shortcuts.

  • Markdown Basics: Enhance your notebooks with formatting.

  • Saving and Exporting Notebooks: Keep your work safe and shareable in various formats.

  • Sharing Notebooks: Use platforms like GitHub and nbviewer for collaboration and presentation.

  • Jupyter Extensions: Customize and extend the functionality of your notebooks.

  • Example Project: Walk through a simple data analysis project to put your learning into practice.

This guide is designed to make your start with Jupyter as smooth as possible, providing a comprehensive overview of its features and how to use them effectively.

What is Jupyter?

Jupyter is a free tool you can use on the internet to create and share documents that have live code, math problems, charts, and text. It started with the IPython project, which was about making a better way to write and run Python code. Later, it grew to include other languages like R and Julia, turning into what we now know as Jupyter.

The main feature of Jupyter is the Jupyter Notebook. This is a place where you can:

  • Live code - Write and run pieces of code one at a time. It works with languages like Python, R, and Julia.

  • Visualizations - Show graphs, pictures, videos, and more right in your document. It's useful for looking at data in different ways.

  • Equations - Write out math equations neatly in your document.

  • Text - Use simple text to explain things, ask questions, or give instructions using Markdown.

Jupyter is great for a few reasons:

  • Experimentation - You can change your code and see what happens right away, without having to start over.

  • Communication - You can tell a full story with data, code, and visuals all in one place.

  • Collaboration - You can share your work with others, letting them add to it or learn from it.

Jupyter Notebook makes working with data easier and is very popular for data science. This guide is all about how to use Jupyter Notebook for your data projects.

Prerequisites

Before you dive into Jupyter Notebooks, it helps to know a bit about certain programming ideas and tools.

Python

It's good to know some Python since Jupyter Notebooks mainly run Python code. You don't have to be a pro, but understanding simple things like:

  • What variables are and the types of data they can hold

  • How to organize data into lists or dictionaries

  • How to use loops and if-else statements

  • How to make and use functions

  • How to bring in extra code with libraries

will set you up to start using notebooks more smoothly.

pandas and NumPy

pandas

Knowing how to use pandas and NumPy is also a plus, but not a must. pandas is a tool that makes it easy to:

  • Bring in, change, and check out data

  • Make graphs and charts

  • Clean up and get your data ready

NumPy lets you do math and scientific computing right in Python. Both of these tools work really well with Jupyter notebooks, especially if you're looking to do stuff with data.

Installation Guide

Anaconda

Anaconda

Anaconda is a great starting point for beginners to install Jupyter Notebook. It bundles Jupyter and lots of other useful data science tools in one easy installation.

To get Anaconda:

  • Visit the Anaconda website and download the latest version for Python 3.x for your operating system.

  • Run the installer and just go with the setup suggestions it offers.

  • After installing, look for "Jupyter Notebook" in your start menu or applications folder and open it.

  • A web page should open showing the Jupyter dashboard, where you can create a new notebook!

Anaconda includes not just Jupyter but also important tools like NumPy, pandas, Matplotlib, which are great for data work. It's an easy way to get all you need without the fuss of setting up each tool separately.

Anaconda makes everything simpler for beginners, making it the best choice for an easy start.

pip

You can also choose to install Jupyter using pip, Python's own package manager. This method lets you pick what to install more specifically.

To use pip:

  • Make sure your computer has Python 3.3 or newer.

  • Open a command prompt or terminal and type: pip install jupyter.

  • After it's done, type jupyter notebook to open the Jupyter dashboard.

Choosing pip means you start with just Jupyter, and then you can add other tools like NumPy or pandas as you need them. This path requires a bit more work to set up everything but gives you control over your setup.

Whether you go for Anaconda or pip depends on whether you prefer an all-in-one solution or building your setup piece by piece.

Launching Jupyter Notebook

Jupyter Notebook

Getting started with Jupyter Notebook is pretty straightforward. You just need to get it running on your computer. Here's how you do it step by step:

  • Open the command line tool on your computer (that's Command Prompt for Windows users or Terminal for Mac and Linux users).

  • Go to the folder where you want to keep your notebooks. You can do this by typing something like:

cd Documents/mynotebooks

and then hitting Enter.

  • Now, you just need to start Jupyter Notebook by typing:
jupyter notebook

and pressing Enter.

  • Doing this opens up Jupyter Notebook in your web browser. It's like starting a mini website on your computer that only you can access to work on your notebooks.

Once you're in, you'll see the Jupyter dashboard. It's kind of like the main menu. From here, you can:

  • Look at all your files and notebooks in one spot

  • Make new notebooks or other files

  • Open up a command line interface (CLI) inside Jupyter Notebook

To create a new notebook, just click the "New" button at the top right, then pick "Python 3" from the "Notebooks" section. This opens a new notebook where you can start coding in Python, write with Markdown, or crunch numbers with data analytics using pandas.

Here are a few extra tips:

  • Always start Jupyter Notebook from the folder where you want your files to be saved.

  • You can visit the Jupyter dashboard anytime by typing http://localhost:8888 in your web browser's address bar.

  • The command jupyter notebook is what gets everything going.

  • To stop the Jupyter server, just press Ctrl-C in the command line window where it's running.

Creating Your First Notebook

Starting with Jupyter Notebooks is pretty straightforward. Your first step is to get the Jupyter Notebook dashboard up and running. This dashboard is where you can make new notebooks and look at the ones you've already made.

Launching the Dashboard

Here's how to open the dashboard:

  • Open a terminal or command prompt

  • Go to the folder where you want to keep your notebooks

  • Type jupyter notebook and hit Enter

This action fires up the Jupyter server and pops open the dashboard in your web browser.

Creating a New Notebook

When you're in the dashboard, making a new notebook is easy:

  • Click the "New" button at the top right and pick "Python 3" from the list

  • You'll see a new notebook appear, ready for you to use

This new file ends with .ipynb, which means it's a Jupyter notebook file.

The Notebook Interface

The notebook has a simple setup with cells that can hold either code or text.

  • Code Cells: These are for typing and running Python code

  • Markdown Cells: These let you add text, pictures, and more using Markdown

To add another cell, just hit the + button up top. You can choose between a code cell or a Markdown cell from a list.

Running a code cell is as simple as pressing the play (▶|) button, which runs the code and shows any results right underneath.

With Markdown cells, you can write text, make lists, add links, and more. They help you explain what your code is doing or add important notes.

And there you have it, the basics of making your first Jupyter notebook. Now, you're ready to start coding, jotting down notes, making graphs, and much more.

sbb-itb-bfaad5b

Understanding the Notebook Interface

The Jupyter Notebook interface is a place where you can mix code, data, and notes in an easy-to-use way. Let's break down the main parts:

Code Cells

Code cells are spaces where you can write and run Python code step by step. This is super handy for:

  • Trying out new ideas quickly

  • Getting to know different tools or libraries

  • Organizing and showing your data in cool ways

  • Building things bit by bit

Code cells make experimenting easy and fun.

Markdown Cells

Markdown

Markdown cells let you add text next to your code. You can:

  • Explain what you're thinking or doing

  • Use headings, bold or italic text, and lists

  • Insert images, links, or quotes

  • Give instructions or share important info

  • Share what you've found from your code

Markdown cells are great for making your notebook easy to read and understand.

Kernels

Kernels are like the engine for your code cells. They run the code and remember things like which libraries you've added or what variables you've set up. Although we're mostly using Python, you can switch to other languages like R or Julia by changing the kernel.

Kernels keep your workspace active and ready to go. They make sure your notebook works smoothly from start to finish.

In Jupyter Notebook, these parts come together to create a space where you can write code, add notes, and see your results all in one place. It's a powerful tool for anyone working with data or learning to code.

Keyboard Shortcuts

Jupyter notebooks have some quick keyboard tricks that make it easier for you to work. Here are a few key ones you should know:

  • Esc - Switch between edit mode and command mode in a cell

  • Enter - Switch to edit mode in a cell

  • Up/Down arrow - Move to the cell above or below

  • A or B - Add a new cell above or below the current one

  • X - Cut the selected cell

  • C - Copy the selected cell

  • V - Paste the copied or cut cell

  • D, D (press the D key twice) - Delete the selected cell

  • Z - Undo the last cell deletion

  • Shift - Select more than one cell at a time

Editing Cells

  • Tab - Help with code or add an indent

  • Shift + Tab - Remove an indent

  • Ctrl + / - Make or remove a comment on a line

Cell Execution

  • Ctrl + Enter - Run the current cell

  • Alt + Enter - Run the current cell and add a new one below it

  • 00 (press the 0 key twice) - Restart the notebook's engine

  • I, I (press the I key twice) - Stop the notebook's engine if it's stuck

Kernel Information

  • I - Stop the engine if it's running too long

  • 0, 0 (press the 0 key twice) - Restart the engine

  • Shift + M - Combine selected cells together

You can find all the shortcuts by going to Help > Keyboard Shortcuts in the menu. Getting used to these shortcuts can make moving around and editing your notebook a lot quicker.

Markdown Basics

Headings

To make headings in Markdown, you start with the # symbol before your heading text. The more # symbols you use, the smaller the heading gets.

For example:

This is a big heading

This is a smaller heading

Even smaller

Getting tiny

Very small
smallest

You can use up to 6 levels of headings. Try to use them in order, starting with the biggest.

### __Bold__ and _Italics_

To make text bold, put two asterisks or underscores around it:

this is bold also bold


For italics, use one asterisk or underscore:

this is italic this too


### ~~Strikethrough~~

If you want to show text as crossed out, use two tildes (~) on each side:

~this text is crossed out~


This is handy for showing something that's not correct or changed.

## Saving and Exporting Notebooks

Keeping your work safe is key, so you don't lose what you've done. Jupyter notebooks have easy ways to do this.

### Saving Notebooks

To make sure you don't lose your work, you can:

- Use **File > Save and Checkpoint** from the top menu. This saves your work manually.
- Let Jupyter save your work automatically. Go to **File > Preferences**, find the **Notebook** section, and set **Save notebook interval** to every 5 minutes or another time you like.

Jupyter will show `(checkpoint)` next to your file name when it saves.

Some tips:

- **Save often** - Either save your work yourself or set up auto-save.
- **Checkpoints are backups** - Jupyter makes a backup file so it doesn't change your original file.
- **Make files smaller by clearing output** - If your notebook is getting too big, go to **Cell > All Output > Clear**. This keeps your code but removes the results to make things faster.

### Exporting Formats

If you want to share your notebook or use it in a different way, you can change it into another format, like:

- HTML
- PDF
- .py Python script
- Markdown
- and others

Here's how to change the format:

- Click **File > Download as** in the menu.
- Pick the format you want from the list.
- Choose download options and click "Download" to get your file.

Some popular formats are:

- **HTML** - Anyone can view it online
- **PDF** - Good for printing or sharing
- **.py script** - Lets you run your code outside of Jupyter
- **Markdown** - Makes your notes look nice

Changing the format is useful for sharing your work or using it in different ways.

## Sharing Notebooks

When you share your Jupyter notebooks, you can work with others or show your projects to more people. Here are some easy ways to do it:

### [GitHub](https://github.com)

![GitHub](https://mars-images.imgix.net/seobot/screenshots/github.com-008ec4453ff31513f43893cba7aa31c8.jpg?auto=compress)

GitHub is a place where you can keep your notebooks online. It's good for:

- Putting your notebooks in a spot on [GitHub](https://github.com/) so others can see and use them.
- GitHub shows your notebooks with all the cool graphs and codes right there.
- People can copy your work, make their own changes, and help improve it.
- You can talk about your notebooks with others using GitHub's comment section.
- You can also make your notebooks part of bigger projects that automatically update reports or results.

To share on GitHub:

- Make a new spot (repository) on GitHub, either just for you or for everyone.
- Put your `.ipynb` notebook files there.
- GitHub will show your notebook so anyone can look at it.
- Share the link with whoever you want to see it.

### [nbviewer](https://nbviewer.jupyter.org/)

![nbviewer](https://mars-images.imgix.net/seobot/screenshots/nbviewer.jupyter.org-f770e4e15c7cfc01d9ddc4cb1cf06652.jpg?auto=compress)

Nbviewer is a website that shows your Jupyter notebooks without needing Jupyter itself. It's good because:

- You can share a link to your notebook, and nbviewer will show it.
- It's great for when you want to show your notebook to people who don't have Jupyter.
- It works with notebooks from GitHub, nbviewer, or other places.
- It gives a simple, fixed look at your notebook.

To use nbviewer:

- Put your notebook somewhere online where everyone can get to it, like GitHub.
- Visit [nbviewer.jupyter.org](https://nbviewer.jupyter.org/).
- Put in the web address of your notebook.
- Nbviewer makes a link that shows your notebook.

In short, using places like GitHub and nbviewer makes it easy to share your notebooks with friends or anyone online.

## Jupyter Extensions

Extensions are like add-ons for Jupyter Notebooks. They give you extra tools that don't come with the basic setup. Think of them as apps for your phone that make it do more things. Extensions can help you organize your work better, make your data look nicer, find mistakes in your code, and a lot more.

### What Can Extensions Do?

Extensions can do a bunch of helpful stuff like:

- Make a contents page so you can find your way around
- Show more info about the data you're using
- Time how long your code takes to run
- Add shortcuts for common tasks
- Help check your code for errors
- Let you bring in data from files like CSVs
- Let you save your work in different formats
- Help you keep track of changes to your notebooks
- Make it easier to hide or show parts of your code
- Check your spelling
- And a lot more...

They're all about making your Jupyter Notebook easier and better to use.

### Acquiring and Installing Extensions

There are two main ways to get these extensions:

- **jupyter\_contrib\_nbextensions** - This is a big collection of over 50 extensions you can get all at once. You can find it on GitHub and install it using pip.
- **Individual extensions** - If you need something specific, you can look for just that extension and install it on its own.

To install an extension, you:

- [Use pip](https://jupyter.org/install) to get the extension package.
- Turn it on with: `jupyter nbextension enable EXTENSION_NAME`
- Restart Jupyter to make it work.

There's also a handy tool called **Nbextensions Configurator** that makes it easy to manage your extensions right from Jupyter.

### Enabling and Configuring

After installing, you need to turn extensions on. Here's how:

- Go to the Nbextensions tab.
- Check the box next to the extension you want to use.
- Click the settings icon to adjust it how you like.

Some extensions might need you to set things up a bit more, like telling it how to connect to a database. Always check the instructions for any extra steps.

The configurator tool is great because it lets you turn extensions on or off whenever you want and change their settings easily.

### Getting More from Notebooks

With these extensions, you can do a lot more with your Jupyter Notebooks. They help you work smarter, understand your data better, and share your findings more easily. Extensions are a simple way to make Jupyter Notebooks more powerful and suited to your needs.

## Example Project: Data Analysis

In this section, we'll walk through a simple data analysis project using a Jupyter Notebook. [Here](https://s3.amazonaws.com/dq-blog-files/fortune500.csv) are the steps we'll follow:

### Loading in a Dataset

First off, we need some data. We'll use the well-known Iris flower dataset, which has measurements like petal length and width. Here's how to load it with pandas:

```python
import pandas as pd

iris_df = pd.read_csv("iris.csv")  
print(iris_df.head()) 

This command shows us the first few rows of the dataset.

Exploring the Data

Before we dive into any heavy analysis, let's take a look at our data:

iris_df.info() # get info on column types and count
iris_df.describe() # get summary stats
iris_df.species.value_counts() # see how many of each species we have

These commands help us understand the basics of our dataset.

Data Analysis and Visualization

Now, let's do some analysis, like finding the average measurements for each species:

averages = iris_df.groupby("species").mean()
print(averages)

And let's visualize our data with some charts, for example, a boxplot for petal width:

iris_df.boxplot(column="petal_width", by="species")

This chart helps us see how the petal width varies among the species.

Adding Explanations with Markdown

We can also add notes to our work using Markdown cells:

The Iris dataset contains measurements for 150 iris flowers from 3 different species. We looked at features like petal width and noticed some differences between the species.

The boxplots showed us how the petal width varies between setosa, versicolor, and virginica.

Exporting our Final Report

When we're done, we can turn our notebook into an HTML file to share with others. Just go to File > Download As > HTML (.html).

This way, we've combined code, data checks, charts, and notes into a clear story about our data analysis project.

Conclusion

In this guide for beginners, we've talked about the basics of starting with Jupyter Notebooks for anyone interested in data science and analysis.

Here's a quick recap:

  • What is Jupyter Notebook? - It's a free tool you can use online to combine live code, math, pictures, and text all in one document.

  • Why Jupyter is great for data work - You can run code, see the results, and write notes all in the same place, which makes it easier to figure things out and share your findings.

  • How to get started - You can set it up easily with Anaconda or do it step by step with pip.

  • Opening Jupyter - You start it from your computer's command line and use it in your web browser.

  • Navigating the notebook - It has spaces for code, notes in Markdown, and kernels that do the math and remember your code.

  • Getting going - You learn how to make a new notebook, add code and notes, run the code, and save your work.

  • Useful tools - There are shortcuts for your keyboard, ways to format with Markdown, options to save and share your work, and extra features you can add.

  • A simple project - We showed how to put together a report with code, pictures, and explanations.

Jupyter Notebooks make it straightforward to start coding in Python and dive into data. The setup lets you add to your work bit by bit and keep track of your thoughts as you go.

If you're ready for more, Jupyter has lots to offer:

  • Connecting - You can link your notebooks to bigger data systems like databases or Spark for more complex tasks.

  • Making it your own - You can change how Jupyter looks and works to fit what you need.

  • Adding more tools - There are tons of add-ons for making pretty graphs, checking your code, and being more productive.

  • JupyterLab - A fancier version of Jupyter with extra tools like a terminal, text editor, and data viewer built in.

Jupyter Notebooks are a powerful resource for both beginners and seasoned pros. We suggest you keep exploring to see what else you can do. Look for more guides, tutorials, and tips below to help you on your data science journey with Python and Jupyter.

Is Jupyter good for beginners?

Yes, Jupyter Notebook is a great starting point if you're new to coding or data work. It lets you run code piece by piece, which is helpful when you're just figuring things out. You can mix code, text, and pictures all in one place, making it easier to understand what you're doing. It's a friendly way for beginners to get into programming.

How do I start coding on Jupyter?

To begin coding in Jupyter, first open a new Python notebook from the dashboard. This will give you a blank code cell. Just type your Python code into this cell. After you're done, press SHIFT+ENTER or the play button to run your code. This will show you the results right below the cell. You can add more cells to keep coding by clicking the + button.

What are the basics of Jupyter Notebook?

Here are the essentials:

  • Code cells - Where you type and run your code

  • Markdown cells - For adding notes, images, etc., to explain your code

  • Toolbar - Has buttons for running code, adding cells, and other actions

  • Kernel - The part that runs your code

  • Dashboard - The main page where you find all your notebooks

You can use shortcuts or the menu to move around, run your code, and save your work.

Is Jupyter Notebook good for coding?

Absolutely, Jupyter Notebook is designed to make coding easier and more interactive. Its setup lets you run small bits of code at a time, which is great for testing and seeing results quickly. Plus, you can see your graphs and animations right away. This makes Jupyter an excellent choice for both learning how to code and for more advanced coding projects.

Related posts

Why not level up your reading with

Stay up-to-date with the latest developer news every time you open a new tab.

Read more