Jupyter Notebooks Tutorial for Beginners!
Tags: python, jupyter, beginners, tutorial
Published: 2023-09-06 10:54:34

In the realm of data science, research, and education, the advent of Jupyter Notebooks has revolutionized the way we interact with code, data, and ideas. Jupyter Notebooks, an interactive computing environment, seamlessly blend live code execution, visualizations, and explanatory text into a single dynamic document. This integration empowers individuals to tell compelling stories through code, exploring data, conducting experiments, and sharing insights, all within the same versatile canvas. In this article, we delve into the world of Jupyter Notebooks for Beginners. 

## Jupyter Notebooks for Data Scientists & Developers
![Jupyter Notebooks for Data Scientists](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nxi86qepys9p9ic08nky.png)

Jupyter Notebooks have found a home in a diverse range of fields and professions. Data scientists and analysts utilize them to explore datasets, prototype machine learning models, and visualize results, while researchers employ them for conducting experiments, documenting methodologies, and sharing findings. Educators harness the interactive nature of Jupyter Notebooks to teach programming, mathematics, and scientific concepts in an engaging manner. Developers use Jupyter to create tutorials, document APIs, and test code snippets. 

Even business professionals leverage Jupyter's capabilities for data-driven decision-making and creating interactive reports. In essence, Jupyter Notebooks have become a versatile tool that caters to the needs of professionals across data science, research, education, development, and beyond.

## Jupyter Notebooks and Databases
Jupyter Notebooks and databases are intricately connected, forming a powerful duo for data manipulation and analysis. Jupyter Notebooks provide an interactive environment where you can write code, execute queries, and visualize data on the fly. When working with databases, Jupyter Notebooks can establish connections to various database management systems (DBMS) such as MySQL, PostgreSQL, SQLite, and more. 

This enables direct querying and retrieval of data from databases, facilitating seamless integration of real-time information into your analytical workflows. Whether you're extracting, transforming, or loading data, Jupyter Notebooks provide a platform to refine and analyze database content, aiding in informed decision-making and uncovering insights. This synergy between Jupyter Notebooks and databases empowers users to bridge the gap between raw data and actionable intelligence with greater efficiency and interactivity.

## Jupyter Notebooks Tutorial
### Installing Jupyter Notebook
Before you start, make sure you have Python installed on your computer. You can download Python from the official website: [https://www.python.org/downloads/](https://www.python.org/downloads/)

Once Python is installed, you can use the following steps to install Jupyter Notebook using pip, which is Python's package installer:

Open a command prompt or terminal & run the following command to install Jupyter Notebook:

```
pip install jupyter
```
### Creating and Running a Jupyter Notebook
Now that you have Jupyter Notebook installed, follow these steps to create and run your first notebook:

Run the following command to start Jupyter Notebook

```
jupyter notebook
```

This will open a new tab in your web browser with the Jupyter Notebook interface.
![Jupyter Notebooks tutorial](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uz6ny9oelqxmkcmjqb9t.png)

Click on ‘New’ and select ‘Notebook’. 
![notebook select](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yw3obrwr2mq46pxt6r64.png)

Select ‘Python 3’ as the Kernel to work with. 
![python 3 kernel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kx5ctljvzu95o45smv5m.png)

You should see your jupyter dashboard where you can play around. 

You'll see a cell with an empty input area. This is where you can write and execute Python code.

Let’s start with something simple. 

Add the following code and run.

```
print("Hello, Jupyter!")
```
![hello jupyter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4i6o394nedy3k4x7z770.png)

Let’s extend our experiment with Notebooks.

We need 'pandas' library to demonstrate data manipulation and analysis.

#### Install Pandas:
Open your terminal and run the following command to install the pandas library:

```
pip install pandas
```
Restart the Jupyter notebook

```
jupyter notebook
```
### Create a New Notebook
In the Jupyter Notebook interface, click the "New" button and select "Python 3" to create a new notebook.

In the first cell, let's load a simple dataset and analyze it. Enter the following code and run the cell:

```
import pandas as pd

# Create a simple dataset
data = {
    'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Emily'],
    'Age': [25, 30, 22, 28, 24],
    'Salary': [50000, 60000, 45000, 55000, 52000]
}

# Create a DataFrame
df = pd.DataFrame(data)

# Display the DataFrame
Df
```
![python jupyter tutorial](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4vgcniec43ky2j8jn37.png)

### Data Analysis and Visualization
Let's install the matplotlib library to demonstrate data visualization capabilities within Jupyter Notebook.

```
pip install matplotlib
```

Note: Everytime you install something, please stop (using ctrl+c)and you need to restart Jupyter Notebook to make sure it recognizes the newly installed libraries.

In the next cell, let's perform some basic data analysis and create a plot. Enter the following code and run the cell:

```
import matplotlib.pyplot as plt

# Calculate average age and salary
average_age = df['Age'].mean()
average_salary = df['Salary'].mean()

# Print the calculated values
print("Average Age:", average_age)
print("Average Salary:", average_salary)

# Create a bar plot of salaries
plt.bar(df['Name'], df['Salary'])
plt.xlabel('Name')
plt.ylabel('Salary')
plt.title('Salary Distribution')
plt.show()
```
![jupyter tutorial for beginners](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrymmbzdiwzcq51oh3i2.png)

### Adding Markdown Cells
You can also add explanations and documentation using Markdown cells. Click on the "+" button to insert a new cell, then change the cell type to "Markdown" using the dropdown menu. Enter your Markdown content, such as:

```
Data Analysis Example

In this example, we loaded a simple dataset containing information about individuals' names, ages, and salaries. We performed basic data analysis by calculating the average age and salary. Additionally, we created a bar plot to visualize the salary distribution.

This demonstrates how Jupyter Notebook allows you to integrate code, data analysis, visualizations, and explanations in a single interactive document.
```

![data analysis](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k28hlnf1c218dugsuw1n.png)

### Save and Share
To save your notebook, click the floppy disk icon or use the Ctrl + S shortcut. You can share your notebook by saving it as a .ipynb file and sharing that file with others. Alternatively, you can use platforms like GitHub to share your notebook online.

That's it! This example showcases how you can use Jupyter Notebook for data analysis, visualization, and documentation all in one interactive environment. You can explore more advanced features, libraries, and data as you become more familiar with Jupyter.

### Integrate External Content
You can also integrate external content, such as images, links, and videos, into your notebook. Add a new Markdown cell and insert an image:

```
![Titanic](https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/RMS_Titanic_3.jpg/1024px-RMS_Titanic_3.jpg)

Image Source: [Wikipedia](https://en.wikipedia.org/wiki/RMS_Titanic)
```
![external content](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvhmmqccwjbzn9ibmfn2.png)

## SingleStore Notebooks
The SingleStore Notebook extends the capabilities of Jupyter Notebook to enable data professionals to easily work with SingleStore's distributed SQL database while providing great extensibility in language and data sources. 

Let me walk you through a simple tutorial to show you how intuitive the SingleStore Notebooks feature is.

Sign up to [SingleStore for free](https://www.singlestore.com/cloud-trial/?utm_campaign=singlestore-for-ai&utm_medium=referral&utm_source=pavan&utm_term=jupyternotebooks) and claim your $600 worth of free resources.

Let’s go to SingleStore Notebooks
![start with singlestore notebooks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uskchv84vfgvyeknnoht.png)

Create a new blank Notebook.
![new notebook](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1b764lw2oq47fs22fxrr.png)

Let’s code with [SQrL](https://www.singlestore.com/blog/introducing-sqrl-your-singlestore-co-pilot-/) - which is powered by OpenAI’s GPT-4. It can provide immediate and relevant responses to SingleStoreDB-related questions. It can assist you with deployments, code optimization, integrations, resource management, troubleshooting, etc.

So we will use SQrl’s help to query in our Notebooks and feed some content to our database we created. Make sure you have ‘Code with SQrL’ in the ON mode. 
![Code with SQrL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yp36ivxkpxgq92ex7vre.png)

Let us ask SQrL to create a new database named ‘my database’
![create new database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avgt4snjcxy5ailbznnu.png)

Click on ‘Add Cell & Run’.
![run database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jh140vrjt7qm1a4l3ow.png)

You can also confirm if your database is created.
![database created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ux9vj58mr52fyfemx5md.png)

Select that database you just created and let’s move on to adding some tables and content to our newly created database.

Let’s create a table named ‘dishes’ and add 10 Indian dishes.
![create table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b6tyfabb11ias7lx4z2.png)

Create a column named ‘price’ and add random price to each dish.
![price table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0go8u7k95c07kf5lhdiy.png)

Show the dishes table
![dish table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0zxvw9bcb9dh3rrhn4z.png)

Now, let us ask to show the price for each dish.
![dish and price](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/twcze39mlavo12hqu21t.png)

You can also see your dishes and their price in a pie chart format.
![pie chart table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dn3uf06uksoi6fm0vfkk.png)

This way, you can easily create your Notebooks and save them. Learn more about SingleStore Notebooks. 

Both SingleStore Notebooks and Jupyter Notebooks stand as indispensable tools in the arsenal of modern data professionals and developers, facilitating seamless code development, analysis, and collaboration. Jupyter Notebooks, a well-established and widely embraced platform, have set the precedent for interactive coding environments, enabling users to combine code, visualizations, and explanatory text in a single, shareable document.

With the advent of [SingleStore Notebooks](https://www.singlestore.com/cloud-trial/?utm_campaign=singlestore-for-ai&utm_medium=referral&utm_source=devtoarticle&utm_term=jupyternotebooks), a new horizon of possibilities emerges within the realm of data integration and analysis. Seamlessly integrated with the SingleStoreDB runtime, these notebooks provide a native and efficient interface for users to harness the power of SQL and Python. They empower data engineers, scientists, and app developers by offering a swift and intuitive platform for prototyping, demonstrating, and refining their applications.