Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Chapter2 - Python and Jupyter Notebook

Uploaded by

lyntm125
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Chapter2 - Python and Jupyter Notebook

Uploaded by

lyntm125
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

UNIVERSITY OF ECONOMICS HO CHI MINH CITY

VIETNAM NETHERLANDS PROGRAMME

Python and Jupyter Notebooks

OCTOBER 2022

Instructor: TRAN THI TUAN ANH


OVERVIEW

OVERVIEW

Instructor: TRAN THI TUAN ANH 2 / 31


OVERVIEW

Learning objectives
1 Introduction to Python

2 Introduction to Jupyter Notebook

3 Your very first notebook with Jupyter

Instructor: TRAN THI TUAN ANH 3 / 31


OVERVIEW

Outline:
1 Introduction to Python
What is Python?
What is Python Used For?
Why Python?
2 Jupyter Notebook: How to Use?
What is Jupyter Notebook?
Installation
Creating Your First Notebook
Markdown
Sharing Your Notebooks
Reference: (https://www.dataquest.io/blog/jupyter-notebook-tutorial/ )

Instructor: TRAN THI TUAN ANH 4 / 31


OVERVIEW

1. Introduction to Python
1.1 What is Python?

It is a programming language.
Created in 1991 by Dutch programmer Guido Van Rossum.
It aims to limit code blocks and less busy appearance.
It can be placed as a fourth-generation programming language.
(Source: https://codeinstitute.net/global/blog/what-is-python-used-for/ )

Instructor: TRAN THI TUAN ANH 5 / 31


OVERVIEW

1. Introduction to Python
1.1 What is Python?

First Generation Language : Machine languages. It is


machine-dependent and written in binary code (0/1 form).
Second Generation Language : Assembly languages. It is
human-readable and it can be converted to machine language using
an assembler.
Third Generation Language : Procedural language. Examples of
this type of language are C, PASCAL, FORTRAN, COBOL, etc.
Fourth Generation Language : Non – procedural language. It
enables users to access the database. Examples: SQL, Foxpro, Focus,
etc.
Fifth Generation Language : 5GL. It is based on the concept of
artificial intelligence.Example: PROLOG, LISP, etc.
(Source:
Instructor: TRAN THI TUAN ANH 6 / 31
OVERVIEW

1. Introduction to Python
1.2 What is Python Used For?

AI & Machine Learning


Data Analytics
Web Development: YouTube, Instagram, Dropbox...
Search Engine Optimisation (SEO)
Blockchain
Game Development
Automation
GUI Applications (like Kivy, Tkinter, PyQt etc. )
Web scraping (like Scrapy, BeautifulSoup, Selenium)
Multimedia
...
Instructor: TRAN THI TUAN ANH 7 / 31
OVERVIEW

1. Introduction to Python
1.3 Why Python?

(Source: https://www.kdnuggets.com/2020/06/data-science-tools-
popularity-animated.html )

Instructor: TRAN THI TUAN ANH 8 / 31


OVERVIEW

1. Introduction to Python
1.3 Why Python?

Python’s key features:


Free
Open source
Accessible:People of all ages can learn
Versatile: Python can help you solve problems in many fields
Powerful: From simple to complex tasks

Instructor: TRAN THI TUAN ANH 9 / 31


OVERVIEW

1. Introduction to Python
1.3 Why Python?

Python’s key advantages:


Easy to learn and use. Easy syntax. First-choice for beginners.
Has a vibrant community of professionals.
Broadly adopted and supported
Reliable results and flexible to support new experiments.
Python keeps moving forward

Instructor: TRAN THI TUAN ANH 10 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.1 What is Jupyter Notebook?

The Jupyter Notebook is an open source web application that you


can use to create and share documents that contain live code,
equations, visualizations, and text.
"Jupyter" is a loose acronym meaning Julia, Python and R, but today,
the notebook technology supports many programming languages.
A notebook integrates code and its output into a single document
that combines visualizations, narrative text, mathematical equations,
and other rich media.
Jupyter Notebooks are completely free and open source

Instructor: TRAN THI TUAN ANH 11 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.2 Installation

Two ways to install Jupyter:


By installing Anaconda.
Download the latest version of Anaconda for Python 3.10
Install Anaconda by following the instructions and it includes Jupyter
Or install manually using pip (for more advanced users)
Open Command prompt
Use the following command to update pip:
python -m pip install –upgrade pip
Command to install Jupyter:
python -m pip install jupyter
Command to launch Jupyter
jupyter notebook
Instructor: TRAN THI TUAN ANH 12 / 31
OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook

Running Jupyter

Click the “New” drop-down button in the top-right and select “Python
3”:

Your first Jupyter Notebook will open in new tab

Instructor: TRAN THI TUAN ANH 13 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

1st example
Type print(’Hello World!’) into the cell and click the run button
Notebook Run Button in the toolbar above or press Ctrl + Enter.

2nd example
Type the following command and press Ctrl + Enter.

Instructor: TRAN THI TUAN ANH 14 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Practical Exercises: Find the output of following python programs


Program 1:

Instructor: TRAN THI TUAN ANH 15 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Practical Exercises: Find the output of following python programs


Program 2:

Instructor: TRAN THI TUAN ANH 16 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Practical Exercises: Find the output of following python programs


Program 3:

Instructor: TRAN THI TUAN ANH 17 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Practical Exercises: Find the output of following python programs


Program 4:

Instructor: TRAN THI TUAN ANH 18 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Practical Exercises: Find the output of following python programs


Program 5:

Instructor: TRAN THI TUAN ANH 19 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Practical Exercises: Find the output of following python programs


Program 6:

Instructor: TRAN THI TUAN ANH 20 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Practical Exercises: Find the output of following python programs


Program 7:

Instructor: TRAN THI TUAN ANH 21 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Program 8:

Instructor: TRAN THI TUAN ANH 22 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.3 Creating Your First Notebook (cont)

Try to run codes to fulfill some following tasks


1 Calculate the sum of two any number
2 Calculate the area of a rectangle
3 "Guess the number" Game
4 Write 10 first items of Fibonacci sequence:
5 Temperature converter: from Celsius to Fahrenheit
6 Run simple linear regression

Instructor: TRAN THI TUAN ANH 23 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.4 Markdown

You can use Markdown to format documentation you add to Markdown


cells in your Jupyter notebook.
Headings: Use the number sign (#) followed by a blank space for
notebook titles and section headings:
# for titles
## for major headings
### for subheadings
#### for 4th level subheadings
Emphasis: Use the following code to emphasize text:
Bold text: __string__ or **string**
Italic text: _string_ or *string*

Instructor: TRAN THI TUAN ANH 24 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.4 Markdown (cont)

You can use Markdown to format documentation you add to Markdown


cells in your Jupyter notebook.
Bullets:
A hyphen (-) followed by one or two spaces
A space, a hyphen (-) and a space
An asterisk (*) followed by one or two spaces
Numbered lists:
To create a numbered list, enter 1. followed by a space
For simplicity, you use 1. before each entry. The list will be numbered
correctly when you run the cell.

Instructor: TRAN THI TUAN ANH 25 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.4 Markdown (cont)

Example:

Instructor: TRAN THI TUAN ANH 26 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.4 Markdown (cont)

Practice Your Markdown Skills


Open or create a new Jupyter Notebook file
Add a new Markdown cell and include
A title for the notebook
A bullet list with
A bold word for Author: and then add text for your name.
A bold word for Date: and then add text for today’s date.
Add another Markdown cell and include:
A list of your top three favorite foods

Instructor: TRAN THI TUAN ANH 27 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.4 Sharing Your Notebooks

Before You Share


1 Click “Cell > All Output > Clear”
2 Click “Kernel > Restart and Run All”
Exporting Your Notebooks
“File > Download As.”

Instructor: TRAN THI TUAN ANH 28 / 31


OVERVIEW

2. Jupyter Notebook: How to Use?


2.4 Sharing Your Notebooks

Export to PDF with nbconvert


There are two options:
export to PDF via LaTex
export to PDF via HTML (Recommended).
How to export to PDF via HTML"
run Anaconda prompt
Run command
pip install nbconvert[webpdf]
And one more command
jupyter nbconvert –to webpdf –allow-chromium-download
your-notebook-file.ipynb
(Note: changeyour-notebook-file by your own file name )
Instructor: TRAN THI TUAN ANH 29 / 31
OVERVIEW

2. Jupyter Notebook: How to Use?

Tasks in Pairs
1 Create a list of your favorite fruits and print each fruit in the list
2 Write a program that prints the first 10 even numbers.
3 Write a program that checks whether a number is positive, negative,
or zero.
4 Generate a scatter plot using randomly generated data points.
5 Generate a histogram plot to visualize the distribution of a dataset.
6 Implement a simple linear regression model using a small dataset.
7 Create a heatmap to visualize the correlation between different
variables.
8 Create multiple plots within a single figure using subplots.
Submit your Jupyter file or pdf on the link
Instructor: TRAN THI TUAN ANH 30 / 31
OVERVIEW

THE END

THANK YOU FOR LISTENING

Instructor: TRAN THI TUAN ANH 31 / 31

You might also like