Jupyter Notebook Tutorial / Ipython Notebook Tutorial
Introduction to Jupyter Notebook
In this tutorial, we will learn how to build a Jupyter Notebook. A Jupyter Notebook is a web application that combines live code, visualizations, and explanatory text in one place.
What is Jupyter Notebook?
- A notebook is a web application that allows you to combine live code, visualizations, and explanatory text.
- It provides an interactive environment where you can change code and see the results immediately.
- You can also include visualizations such as charts, tables, and videos.
- The rich text formatting makes it easy to share research or findings with others.
Installing Jupyter Notebook
- There are two ways to install Jupyter Notebook: through Anaconda or using pip.
- Installing Anaconda is highly recommended as it includes additional packages.
- To launch Jupyter Notebook after installation, open the command prompt and type
jupyter notebook.
Understanding the Architecture of Jupyter Notebook
- The notebook has a front-end UI running in a web browser and a server running in the background.
- The server communicates with the kernel to execute code and send output back to the browser.
Creating Your First Notebook
- To create a new notebook, click on "New" and select "Python".
- In this tutorial, we will build a notebook that retrieves live stock prices using the pandas Python module and plots them as charts and tables.
- Code cells are used for writing code, while markdown cells are used for explanatory text.
Retrieving Live Stock Prices
In this section, we will retrieve live stock prices using pandas and display them as charts and tables.
Code Snippet
import pandas as pd
df = pd.read_csv('stock_prices.csv')
df.head()
- The code snippet uses the pandas library to read stock prices from a CSV file.
- The
dfvariable represents a pandas DataFrame, which is used to store and manipulate tabular data.
- The
df.head()function displays the first few rows of the DataFrame as a table.
Executing Code in Jupyter Notebook
This section explains how code execution works in Jupyter Notebook.
Code Execution
- When you execute a code cell, it sends a JSON message to the notebook server.
- The notebook server uses the kernel to run the code and returns the output back to the browser.
- Each executed line is marked with a line number and sometimes a star (*) indicating that it is currently executing.
Plotting Closing Price of Stock
In this section, the speaker discusses how to plot the closing price of a stock on a daily basis. They explain that the chart should be in green color and demonstrate how to run specific cells or lines using buttons or keyboard shortcuts.
Using Line Magic for Live Plotting
- The speaker introduces the concept of line magic and explains that it is needed to plot the chart immediately after executing a specific line.
- They demonstrate how to use the "%%matplotlib inline" line magic to achieve live plotting.
- By executing this line, the chart will be plotted as soon as it finishes executing.
- The speaker mentions that they will provide more details about line magic later.
Cell Manipulation and Shortcuts
This section focuses on cell manipulation options and shortcuts available in Jupyter Notebook.
Cell Manipulation Options
- The speaker explains that there are several buttons available for cell manipulation, such as removing a cell or inserting a cell above or below.
- They demonstrate how to remove a cell using the corresponding button.
- To insert a cell above, they show how to use the shortcut "A" or "B" for inserting a cell below when a specific cell is selected.
- The speaker also mentions that there are keyboard shortcuts available for these actions.
Saving Notebook and File Naming
- The speaker points out the button used for saving the Jupyter Notebook file.
- They recommend saving the file after adding some code.
- By clicking on the save button, it saves the file as "untitled", but users can click on it again to give it a name.
Introduction to Line Magic Commands
In this section, the speaker introduces line magic commands and explains how to access a list of available magic commands.
Accessing Magic Commands
- The speaker mentions that when encountering lines starting with "%", it usually indicates a line magic or cell magic command.
- They demonstrate how to see all the available magic commands by executing "%lsmagic".
- By executing this command, a list of line magics and cell magics will be displayed.
Exploring Line Magic Commands
This section explores some of the line magic commands and their functionalities.
Understanding Time Magic Command
- The speaker highlights the "%time" magic command, which is used to measure the performance of a Python statement execution.
- They explain that by using "%time print('Hello World')", it will display the time taken to execute the print statement.
Using System Command with Line Magic
- The speaker introduces the "%system" line magic command, which allows running any UNIX command.
- They demonstrate how to use "%system pwd" to show the present working directory.
- Additionally, they show how to use "%system ls" to list all files in the current working directory.
- The speaker mentions that an exclamation mark can also be used as a shortcut for running system commands.
Plotting Volume as Bar Chart
In this section, the speaker demonstrates how to plot volume data as a bar chart using matplotlib.
Plotting Volume Data
- The speaker explains that they have volume data in their dataframe and want to plot it as a bar chart.
- They demonstrate how to use "dataframe.plot.bar()" method with the y-axis specified as "volume".
- By executing this code, it plots a bar chart representing the volume data.
Timestamps are provided for each section.
t=16m9s Introduction and Purpose of the Tutorial
The speaker explains the purpose of the tutorial and how to add explanatory text using markdown in Jupyter Notebook.
Adding Explanatory Text
- To add explanatory text, insert a new cell and change its type to markdown.
- Markdown cells allow for formatting options such as making text bold or creating lists.
- Use double hash (##) to create headers of different levels.
- Use single star (*) to make text italic.
Exploring Markdown Properties
The speaker demonstrates various markdown properties that can be used in Jupyter Notebook.
Formatting Index
- To explore more markdown properties, go to "Help" and select "Markdown Help".
- Hash (#) is used to create headers of different levels.
- Single star (*) is used to make text italic.
t=19m0s Adding Pandas Logo and Styling
The speaker shows how to add an image, specifically the Pandas logo, using markdown in Jupyter Notebook.
Adding an Image
- Insert a new cell and change its type to markdown.
- Copy the image address from a website (e.g., pandas website).
- Use the following syntax:

- Replace
alt_textwith a description of the image.
- Replace
image_addresswith the copied image address.
Exporting Jupyter Notebook
The speaker explains how to export a Jupyter Notebook as HTML or Python file for sharing with others.
Exporting Options
- To share a notebook, go to "File" > "Download as" > "Notebook (.ipynb)".
- Export as HTML: "File" > "Download as" > "HTML (.html)".
- Export as Python file: "File" > "Download as" > "Python (.py)".
Exploring Jupiter Notebook Gallery
The speaker suggests exploring the Jupiter Notebook Gallery to find interesting notebooks created by others.
Finding Interesting Notebooks
- Search for "Jupiter Notebook Gallery" on Google.
- Explore various notebooks on different topics, such as data analysis and neural networks.
- Notebooks have the extension ".ipynb", which stands for IPython Notebook.
Conclusion and Further Exploration
The speaker concludes the tutorial and encourages further exploration of Jupiter Notebook's features.
Final Remarks
- This tutorial provides a starting point for using Jupyter Notebook.
- There are many other interesting features not covered in this video.
- IPython Notebooks have the extension ".ipynb".
The transcript is already in English, so there is no need to respond in a different language.