Python Installation Data Science
Introduction
Digital computers can understand instructions given to them in zeros and
ones, where a one means turning ON a specific part of the central
processing unit of a computer, and a zero means turning OFF that part. The
computer instructions in the form of 0s and 1s are called machine language
or machine code. It is very difficult for humans to understand and program
the computer using machine language. Instead of using a low-level machine
language, we use easily understandable higher-level languages that
automatically translate high-level instructions into machine language. There
is a large pool of higher-level languages such as Java, C++, Visual Basic,
MATLAB, etc. These languages are good for many tasks; however, these are
not suitable for data science. On the contrary, Python provides a rich source
of specialized libraries and packages that make it the right tool for data
science. This chapter provides the reader with a quick guide and a step-by-
step process of installing and getting started with Python for data science.
2.2. Installation and Setup
There are different ways to download and install Python 3, the latest release
of Python, which is widely used and supported by third-party libraries. One
popular way is to download the software from the official website Python
Software Foundation [Link] . However,
installing Python from the aforementioned link does not accompany many
libraries and packages useful for data science tasks. These add-ons have to
be installed separately. Therefore, we do not follow this method here. Here,
we use the Anaconda distribution of Python for data science and machine
learning applications. Anaconda is a free and open-source distribution that
includes data science libraries for Windows, Linux, and macOS operating
systems. Since packages are included in this distribution, we should have
high-speed internet and storage to download large installation files.
Figure 2.1: Anaconda Installers for Windows, MacOS, and Linux Individual Edition.
Anaconda Individual Edition can be downloaded from
[Link] , as shown in figure 2.1.
We download the installation file by selecting the proper operating system
and its version—either 32-bit or 64-bit—from the aforementioned link. We
present a step-by- step installation guide for the installation and setup of
Python using Anaconda.
2.2.1. Windows
1. Download the graphical Windows installer from
[Link]
2. Double-click the downloaded file. Then, click Continue to begin the
installation.
3. Answer the following prompts: Introduction, Read Me, and License
screens
4. Next, click the Install button. Install Anaconda in a specified directory
(Anaconda3_Python) given in the installation.
2.2.2. Apple OS X
1. Download the graphical MacOS installer from
[Link]
2. Double-click the downloaded file. Click Continue to begin the installation.
3. Next, click the Install button. Install Anaconda in the specified directory.
4. Follow the instructions as was given with Windows installation.
2.2.3. Creating and Using Notebooks
After the installation of Python is complete, it is time to explore the features
of the language. To start working, we have to launch Jupyter Notebook
accompanied with Anaconda installation. It can be launched by:
the Anaconda Navigator by searching it in Windows Search Box. A new win
will open, as shown below. Select and open the Jupyter Notebook from top
right side of the page.
• Select and open the Jupyter Notebook from top right side of the page.
writing Jupyter Notebook in Windows Search Box , as shown in figure
2.15.
Figure : Creating a new Python 3 file in Jupyter Notebook.
A browser page will open, as shown below. To create a new notebook, go to
New on the top right side of the page and select Python 3.
Note that the notebook contains a cell that is highlighted, indicating that we
can begin typing code in it. The title of the notebook is Untitled1. We can
rename our Notebook by clicking on Untitled1 next to the Jupyter icon in the
top left corner of the Notebook.
Make sure the highlighted box in the middle of the figure is selected to Code.
The box highlighted in the bottom of the figure has In [ ]: written next to it.
This is the place where we write Python code. We are now ready to write
our first program.
This Notebook doesn’t contain anything yet. Place the cursor in the cell.
Type print(“Hello World”). Then, click on the Run button on the toolbar. The
output of this line of code appears on the next line, as shown in the figure
below.
We can also hit shift+enter keys together to get the output of the
aforementioned print command.
The output is part of the same cell as the code. Visually, Notebook
separates the output from the code. Notebook automatically creates a new
cell for the next commands to be entered.
The cells in the Jupyter Notebook are used to enter either code or
markdown. A markdown cell can be used to display text which can be
formatted using a markdown language. A cell can be converted to a
markdown cell from the cell menu, as shown in the figure that follows. The
In [ ] prompt before the cell disappears, indicating that anything written in
the cell will not run as Python code.
When the Python code is run, it is executed on a line to line basis, i.e., the
Python code is interpreted. This interpreter acts as a calculator. We can
type an expression in the cell, and it will return us the output value.
This Notebook can be downloaded by going to the File dropdown menu,
selecting Download as and clicking on Notebook (.ipynb). Once the file is
downloaded, it can be opened and used in the future by going to the File
drop-down menu and clicking open.