Appendix A. Installation and setup

Welcome to the supplementary material! This appendix walks you through installing the Python programming language and the pandas library for the macOS and Windows operating systems. A library (also called a package) is a toolbox of features that expands a core programming language’s functionalities—an expansion pack or add-on that offers solutions to common challenges that developers face when working with the language. The Python ecosystem includes thousands of packages for domains such as statistics, HTTP requests, and database management.

A dependency is a piece of software that we need to install to run another piece of software. Pandas is not a stand-alone package; it has a set of dependencies including the libraries NumPy and pytz. These libraries may require their own dependencies. We don’t have to understand what all these other packages do, but we need to install them for pandas to function.

A.1 The Anaconda distribution

Open source libraries are often developed by independent teams of contributors on different timelines. Unfortunately, the isolated development cycles can introduce compatibility issues between library versions. Installing the latest version of a library without upgrading its dependencies may render it dysfunctional, for example.

To simplify the installation and management of pandas and its dependencies, we’ll rely on a Python distribution called Anaconda. A distribution is a collection of software that bundles multiple applications and their dependencies in one straightforward installer. With a user base of more than 20 million, Anaconda is the most popular distribution for getting up and running with data science in Python.

Anaconda installs Python and a powerful environment management system called conda. An environment is an independent sandbox for code execution—a playground of sorts where we can install Python and a selection of packages. To experiment with a different version of Python, a different version of pandas, a different combination of packages, or anything in between, we create a new conda environment. Figure A.1 depicts three hypothetical conda environments, each with a different version of Python.

Figure A.1 Three Anaconda environments with different Python versions and different packages

The advantage of environments is isolation. Changes in one environment do not affect any other environment, as conda stores them in different folders. Thus, we can easily work on multiple projects, each of which requires a different configuration. When you’re installing packages to an environment, conda also installs the appropriate dependencies and ensures compatibility between different library versions. In short, conda is an effective way to enable multiple installations and configurations of Python tools on your computer.

That’s a big-picture introduction! Now let’s get down to business and install Anaconda. Head to www.anaconda.com/products/individual, and find the section of the page with installer downloads for your operating system. You’ll likely see multiple versions of the Anaconda installer:

  • If you’re given a choice between a Graphical Installer and a Command Line Installer, choose the Graphical Installer.

  • If you’re given a choice of Python versions, target the most up-to-date one. As with most software, a larger version number denotes a more recent release. Python 3 is newer than Python 2, and Python 3.9 is newer than Python 3.8. When you’re learning a new technology, it’s best to get started with the latest release. Don’t worry; conda permits you to create environments with earlier versions of Python if you need them.

  • If you’re a Windows user, you may be given a choice between a 64-bit and a 32-bit installer. We’ll discuss which one to select in section A.3.

At this point, the setup process diverges for the macOS and Windows operating systems. Find the appropriate subsection in this appendix, and continue from there.

A.2 The macOS setup process

Let’s walk through installing Anaconda on a macOS computer.

A.2.1 Installing Anaconda in macOS

Your Anaconda download will consist of a single .pkg installer file. The filename will likely include the Anaconda version number and the operating system (such as Anaconda3-2021.05-MacOSX-x86_64). Locate the installer in your file system, and double-click it to start the installation.

Click the Continue button on the first screen. On the README screen, the installer provides a quick overview of Anaconda that is worth perusing (see figure A.2).

Figure A.2 Anaconda installation screen on a macOS computer

The installation creates a starter conda environment called base with a collection of more than 250 preselected data analysis packages. You will be able to create additional environments later. The installer also informs you that it will activate this base environment whenever you start your shell; we’ll discuss how this process works in section A.2.2. For now, trust that this part of the installation process is required, and proceed onward.

Continue through any remaining screens. Accept the license agreement and the space requirements. You’ll be given the option to customize your installation directory; whether you do is entirely up to you. Note that the distribution is self-contained; Anaconda installs itself within one directory on your computer. Thus, if you’d ever like to uninstall Anaconda, you can delete that directory.

Installation may take up to a few minutes. When it completes, click Next until you exit the installer.

A.2.2 Launching Terminal

Anaconda ships with a graphical program called Navigator that makes it easy to create and manage conda environments. Before we launch it, though, we’ll use the more traditional Terminal application to issue commands to the conda environment manager.

Terminal is an application for issuing commands to the macOS operating system. Before modern graphical user interfaces (GUIs) existed, users relied exclusively on text-based applications to interact with the computer. In Terminal, you enter text and then press the Enter key to execute it. I’d like us to master Terminal before Anaconda Navigator because it’s important to understand the complexity that a piece of software abstracts from us before we rely on its shortcuts.

Open a Finder window, and navigate to the Applications directory, where you’ll find the Terminal application within the Utilities folder. Launch the application. I also recommend dragging the Terminal app’s icon to the Dock for easy access.

Terminal should list the active conda environment inside a pair of parentheses before its flashing prompt. As a reminder, Anaconda created a base starter environment during installation. Figure A.3 shows a sample Terminal window with the base environment activated.

Figure A.3 Terminal on a macOS machine. The active conda environment is base.

Anaconda will activate the conda environment manager and this base environment whenever we start Terminal.

A.2.3 Common Terminal commands

We need to memorize only a few commands to work effectively with Terminal. In Terminal, we can navigate through our computer’s directories the same way that we do in the Finder. The pwd (print working directory) command outputs the folder we are in:

(base) ~$ pwd
/Users/boris

The ls (list) command lists the files and folders inside the current directory:

(base) ~$ ls
Applications Documents    Google Drive Movies       Pictures     anaconda3
Desktop      Downloads    Library      Music        Public

Some commands accept flags. A flag is a configuration option we add after a command to modify how it executes. Its syntax consists of a sequence of dashes and text characters. Here’s one example. The ls command by itself shows only public files and folders. We can add the --all flag to the command to display the hidden files as well. Some flags support multiple syntax options. ls -a , for example, is a shortcut for ls --all. Try both commands for yourself.

The cd (change directory) command navigates into a specified directory. Enter the directory name immediately after the command, making sure to include a space. In the next example, we navigate into the Desktop directory:

(base) ~$ cd Desktop

We can output our current location with the pwd command:

(base) ~/Desktop$ pwd
/Users/boris/Desktop

A pair of dots after cd navigates upward in the folder hierarchy:

(base) ~/Desktop$ cd ..
 
(base) ~$ pwd
/Users/boris

Terminal has a powerful autocomplete feature. Inside your user directory, enter cd Des and press the Tab key to autocomplete it to cd Desktop. Terminal looks at the list of available files and folders, and determines that only Desktop matches the Des pattern we typed. If there are multiple matches, Terminal will complete a portion of the name. If a directory contains two folders, Anaconda and Analytics, and you enter the letter A, Terminal will autocomplete Ana, the common letters in the two options. You’ll have to type an additional letter and press the Tab key again for Terminal to autocomplete the remainder of the name.

At this point, we’ve acquired all the knowledge we need to start working with the conda environment manager. Skip to section A.4, where we’ll meet up with our Windows friends and set up our first conda environment!

A.3 The Windows setup process

Let’s walk through installing Anaconda on a Windows computer.

A.3.1 Installing Anaconda in Windows

The Anaconda installer for Windows is available in both 32-bit and 64-bit versions. These options describe the type of processor installed with your computer. If you are unsure which option to download, open the Start menu, and choose the System Information app. On the app’s main screen, you will see a table consisting of Item and Value columns. Look for the System Type item; its value will include x64 if your computer runs a 64-bit version of Windows or x86 if your computer runs a 32-bit version of Windows. Figure A.4 shows the System Information app on a Windows computer with the System Type row highlighted.

Figure A.4 The System Information app on a 64-bit Windows computer

Your Anaconda download will consist of a single .exe installer file. The filename will include the Anaconda version number and the operating system (such as Anaconda3-2021.05-Windows-x86_64). Locate the file on your file system and double-click it to launch the installer.

Proceed through the first few installation screens. You will be prompted to accept the license agreement, choose whether to install Anaconda for one or all users, and select the installation directory. Selecting the default options is fine.

When you reach the Advanced Installation Options screen, it might be a good idea to deselect the Register Anaconda As My Default Python check box if you already have Python installed on your computer. Deselecting the item prevents the installation from setting Anaconda as the default Python version on your computer. If you’re installing Python for the first time, keeping the option selected should be fine.

The installation creates a starter conda environment called base with a collection of more than 250 preselected data analysis packages. You will be able to create additional environments later.

Installation can take up to a few minutes. Figure A.5 shows a sample of the installation process. When installation is complete, exit the installer.

Figure A.5 In-progress Anaconda installation on a Windows computer

If you ever want to uninstall Anaconda, launch the Start menu, and choose Add or Remove Programs. Locate the Anaconda program, click the Uninstall button, and follow the steps in the prompt to remove the distribution from your computer. Note that this process will remove all conda environments as well as their installed packages and Python versions.

A.3.2 Launching Anaconda Prompt

Anaconda ships with a graphical program called Navigator that makes it easy to create and manage conda environments. Before we launch it, though, we’ll use a more traditional command-line application to issue commands to the conda environment manager. It’s important to understand the problems that Navigator solves for us before we rely on its shortcuts.

Anaconda Prompt is an application for issuing text commands to the Windows operating system. We enter a command and then press the Enter key to execute it. Before modern GUIs existed, users relied exclusively on command-based applications like this one to interact with the computer. Open the Start menu, find Anaconda Prompt, and launch the application.

Anaconda Prompt should always list the active conda environment in a pair of parentheses before its flashing prompt. Right now, you should see base, the starter environment that Anaconda created during installation. Figure A.6 displays Anaconda Prompt with an active base environment.

Figure A.6 Anaconda Prompt on a Windows machine. The active conda environment is base.

Anaconda Prompt will activate the base environment when it launches. In section A.3.4, we’ll walk through how to create and activate new environments with conda.

A.3.3 Common Anaconda Prompt commands

We need to memorize only a few commands to work effectively with Anaconda Prompt. We can navigate through our computer’s directories the same way that we do in Windows Explorer. The dir (directory) command lists all files and folders in the current directory:

(base) C:UsersBoris>dir
 Volume in drive C is OS
 Volume Serial Number is 6AAC-5705
 
 Directory of C:UsersBoris
 
08/15/2019 03:16 PM <DIR> .
08/15/2019 03:16 PM <DIR> ..
09/20/2017 02:45 PM <DIR> Contacts
08/18/2019 11:21 AM <DIR> Desktop
08/13/2019 03:50 PM <DIR> Documents
08/15/2019 02:51 PM <DIR> Downloads
09/20/2017 02:45 PM <DIR> Favorites
05/07/2015 09:56 PM <DIR> Intel
06/25/2018 03:35 PM <DIR> Links
09/20/2017 02:45 PM <DIR> Music
09/20/2017 02:45 PM <DIR> Pictures
09/20/2017 02:45 PM <DIR> Saved Games
09/20/2017 02:45 PM <DIR> Searches
09/20/2017 02:45 PM <DIR> Videos
              1 File(s) 91 bytes
             26 Dir(s) 577,728,139,264 bytes free

The cd (change directory) command navigates into a specified directory. Enter the directory name immediately after the command, making sure to include a space. In the next example, we navigate into the Desktop directory:

(base) C:UsersBoris>cd Desktop
 
(base) C:UsersBorisDesktop>

A pair of dots after cd navigates upward in the folder hierarchy:

(base) C:UsersBorisDesktop>cd ..
 
(base) C:UsersBoris>

Anaconda Prompt has a powerful autocomplete feature. Inside your user directory, enter cd Des and press the Tab key to autocomplete it to cd Desktop. Anaconda Prompt looks at the list of available files and folders, and determines that only Desktop matches the Des pattern we typed. If there are multiple matches, Anaconda Prompt will complete a portion of the name. If a directory contains two folders, Anaconda and Analytics, and you enter the letter A, Anaconda Prompt will autocomplete Ana, the common letters in the two options. You’ll have to type an additional letter and press the Tab key again for Prompt to autocomplete the remainder of the name.

At this point, we have all the knowledge we need to start working with the conda environment manager. Let’s create our first conda environment!

A.4 Creating a new Anaconda environment

Congratulations—you’ve successfully installed the Anaconda distribution on your macOS or Windows machine. Now let’s create a sample conda environment that we’ll use as we work through the book. Please note that the code samples in this section are from a macOS computer. Although outputs may vary slightly between the two operating systems, the Anaconda commands remain the same.

Open Terminal (macOS) or Anaconda Prompt (Windows). Anaconda’s default base environment should be active. Look for the presence of parentheses with the word base to the left of the prompt.

First, let’s confirm that we successfully installed the conda environment manager by issuing a sample command. Here’s an easy one: ask conda for its version number. Note that your version may differ from the one in the following output, but as long as the command returns any number at all, conda is successfully installed:

(base) ~$ conda –-version
conda 4.10.1

The conda info command returns a list of technical details about conda. The output includes the currently active environment and its location on your hard drive. Here is an abbreviated version of the output:

(base) ~$ conda info
 
     active environment : base
    active env location : /opt/anaconda3
            shell level : 1
       user config file : /Users/boris/.condarc
 populated config files : /Users/boris/.condarc
          conda version : 4.10.1
    conda-build version : 3.18.9
         python version : 3.7.4.final.0

We can use flags to customize and configure conda commands. A flag is a configuration option we add after a command to modify how it executes. Its syntax consists of a sequence of dashes and text characters. The --envs flag to the info command lists all environments and their locations on the computer. An asterisk (*) marks the active environment:

(base) ~$ conda info --envs
# conda environments:
#
base                  *  /Users/boris/anaconda3

Every conda command supports the --help flag, which outputs documentation for the command. Let’s add the flag to the conda info command:

(base) ~$ conda info --help
usage: conda info [-h] [--json] [-v] [-q] [-a] [--base] [-e] [-s]
                  [--unsafe-channels]
 
Display information about current conda install.
 
Options:
 
optional arguments:
  -h, --help         Show this help message and exit.
  -a, --all          Show all information.
  --base             Display base environment path.
  -e, --envs         List all known conda environments.
  -s, --system       List environment variables.
  --unsafe-channels  Display list of channels with tokens exposed.
 
Output, Prompt, and Flow Control Options:
  --json             Report all output as json. Suitable for using conda
                     programmatically.
  -v, --verbose      Use once for info, twice for debug, three times for
                     trace.
  -q, --quiet        Do not display progress bar.

Let’s create a new playground to play in. The conda create command generates a new conda environment. We have to use the ––name flag to provide a name for the environment. I’ve chosen a fitting title of pandas_in_action; you’re welcome to choose whatever environment name you like. When conda prompts for confirmation, enter y (for yes) and press Enter to confirm:

(base) ~$ conda create --name pandas_in_action
Collecting package metadata (current_repodata.json): done
Solving environment: done
 
## Package Plan ##
 
  environment location: /opt/anaconda3/envs/pandas_in_action
 
 
Proceed ([y]/n)? y
 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate pandas_in_action
#
# To deactivate an active environment, use
#
#     $ conda deactivate

By default, conda installs the latest version of Python in the new environment. To customize the language version, add the keyword python at the end of the command, enter an equal sign, and declare the desired version. The next example shows how to create an environment called sample with Python 3.7:

(base) ~$ conda create --name sample python=3.7

Use the conda env remove command to delete an environment. Provide the --name flag with the environment you’d like to remove. The next code sample deletes the sample environment we created:

(base) ~$ conda env remove --name sample

Now that the pandas_in_action environment exists, we can activate it. The conda activate command sets the active environment in Terminal or Anaconda Prompt. The text in parentheses before the prompt will change to reflect the new active environment:

(base) ~$ conda activate pandas_in_action
 
(pandas_in_action) ~$

All conda commands execute in the context of the active environment. If we ask conda to install a Python package, for example, conda will now install it within pandas_in_action. We want to install the following packages:

  • The core pandas library

  • The jupyter development environment where we’ll be writing our code

  • The bottleneck and numexpr libraries for speed accelerations

The conda install command downloads and install packages in the active conda environment. Add the four packages immediately after the command, separated by spaces:

(pandas_in_action) ~$ conda install pandas jupyter bottleneck numexpr

As mentioned earlier, these four libraries have dependencies. The conda environment manager will output a list of all packages that it needs to install. Following is a shortened version of the output. It’s OK if you see a different list of libraries or version numbers; conda takes care of compatibility.

Collecting package metadata (repodata.json): done
Solving environment: done
 
## Package Plan ##
 
  environment location: /opt/anaconda3/envs/pandas_in_action
 
  added / updated specs:
    - bottleneck
    - jupyter
    - numexpr
    - pandas
 
 
The following packages will be downloaded:
 
    package                    |            build
    ---------------------------|-----------------
    appnope-0.1.2              |py38hecd8cb5_1001          10 KB
    argon2-cffi-20.1.0         |   py38haf1e3a3_1          44 KB
    async_generator-1.10       |             py_0          24 KB
    certifi-2020.12.5          |   py38hecd8cb5_0         141 KB
    cffi-1.14.4                |   py38h2125817_0         217 KB
    ipython-7.19.0             |   py38h01d92e1_0         982 KB
    jedi-0.18.0                |   py38hecd8cb5_0         906 KB
    #... more libraries

Type y for yes and press Enter to install all packages and their dependencies.

If you ever forget the packages installed in an environment, use the conda list command to see a complete list. The output includes each library’s version:

(pandas_in_action) ~$ conda list
 
# packages in environment at /Users/boris/anaconda3/envs/pandas_in_action:
#
# Name                    Version             Build  Channel
jupyter                   1.0.0           py39hecd8cb5_7
pandas                    1.2.4           py39h23ab428_0

If you ever want to remove a package from an environment, use the conda uninstall command. Here’s what that command would look like with pandas:

(pandas_in_action) ~$ conda uninstall pandas

We’re ready to explore our development environment. We can launch the Jupyter Notebook application with the command jupyter notebook:

(pandas_in_action) ~$ jupyter notebook

Jupyter Notebook starts a local server on your computer to run the core Jupyter application. We need a server running continually so that it can observe the Python code we write and execute it immediately.

The Jupyter Notebook application should open in your system’s default web browser. You can also access the application by navigating to localhost:8888/ in the address bar; localhost refers to your computer, and 8888 is the port on which the app is running. Much as a dock includes multiple ports to welcome multiple ships, your computer (localhost) has multiple ports to allow multiple programs to run on your computer’s local server. Figure A.7 shows the main interface of the Jupyter Notebook interface, listing the files and folders in the current directory.

Figure A.7 Jupyter Notebook’s main interface

The Jupyter Notebook interface is similar to the Finder (macOS) or Windows Explorer (Windows). Folders and files are organized in alphabetical order. You can click through folders to navigate into the next directory and use the breadcrumbs on top to navigate upward. Poke around for a few seconds. When you get the hang of navigation, close the browser.

Note that closing the browser does not shut down the running Jupyter server. We need to press the keyboard shortcut Ctrl-C twice in Terminal or Anaconda Prompt to terminate the Jupyter server.

Note that every time you launch Terminal (macOS) or Anaconda Prompt (Windows), you’ll have to activate the pandas_in_action environment again. Although Anaconda’s base environment includes pandas, I recommend creating a new environment for every Python book or tutorial you work through. Multiple environments ensure separation between Python dependencies across different projects. One tutorial may use pandas 1.1.3, for example, and another may use pandas 1.2.0. There are fewer chances for technical errors when you install, upgrade, and work with dependencies in isolation.

Here’s a reminder of what to do each time you launch Terminal or Anaconda Prompt:

(base) ~$ conda activate pandas_in_action
 
(pandas_in_action) ~$ jupyter notebook

The first command activates the conda environment, and the second command launches Jupyter Notebook.

A.5 Anaconda Navigator

Anaconda Navigator is a graphical program for managing conda environments. Although its feature set is not as comprehensive as that of the conda command-line tool, Anaconda Navigator offers a visual, beginner-friendly way to create and manage environments with conda. You can find Anaconda Navigator inside the Applications folder in the Finder (macOS) or on the Start menu (Windows). Figure A.8 shows the home screen of the Anaconda Navigator app.

Figure A.8 Anaconda Navigator home screen

Click the Environments tab on the left menu to display a list of all environments. Select a conda environment to see its installed packages, including their descriptions and version numbers.

On the bottom pane, click the Create button to launch a new environment-creation prompt. Give the environment a name, and select a version of Python to install. The resulting dialog box displays the location where conda will create the environment (figure A.9).

Figure A.9 Creating a new Anaconda environment

To install a package, select an environment in the left list. Above the list of packages, click the drop-down menu and choose All to see all packages (figure A.10).

Figure A.10 Anaconda package search

In the search box on the right, search for a sample library, such as pandas. Locate it in the search results, and select the corresponding check box (figure A.11).

Figure A.11 Searching for and selecting the pandas package in Anaconda Navigator

Finally, click the green Apply button in the bottom-right corner to install the library.

Let’s delete the pandas_playbox environment we created. We don’t need it because we already created a pandas_in_action environment in Terminal or Anaconda Prompt. Make sure to select pandas_playbox in the left-side environment list. Then click the Remove button on the bottom panel and again in the confirmation dialog box (figure A.12).

Figure A.12 Deleting the environment we created in Anaconda Navigator

To launch Jupyter Notebook from Anaconda Navigator, click the Home tab of the left navigation menu. On this screen, you’ll see tiles for the applications installed in the current environment. The top of the screen has a drop-down menu from which you can choose the active conda environment. Make sure to select the pandas_in_action environment we created for this book. Then you can launch Jupyter Notebook by clicking its application tile. This action is equivalent to executing jupyter notebook from Terminal or Anaconda Prompt.

A.6 The basics of Jupyter Notebook

Jupyter Notebook is an interactive development environment for Python, consisting of one or more cells, each of which holds Python code or Markdown. Markdown is a text formatting standard that we can use to add headers, text paragraphs, bulleted lists, embedded images, and more to the Notebook. We use Python to write our logic and Markdown to organize our thoughts. As you proceed through the book, feel free to use Markdown to take notes on the material. The complete documentation for Markdown is available at https://daringfireball.net/projects/markdown/syntax.

On the Jupyter launch screen, click the New button on the right menu, and choose Python 3 to create a new Notebook (figure A.13).

Figure A.13 Creating a Jupyter Notebook

To give the Notebook a name, click the Untitled text at the top and enter a name in the dialog box. Jupyter Notebook saves its files with the .ipynb extension, short for IPython Notebooks, the predecessor of Jupyter Notebooks. You can navigate back to your Jupyter Notebook tab to see the new .ipynb file in the directory.

A Notebook operates in two modes: Command and Edit. Clicking a cell or pressing Enter while the cell is focused triggers Edit mode. Jupyter highlights the cell with a green border. In Edit mode, Jupyter interprets your keyboard presses literally. We use this mode to type characters in a selected cell. Figure A.14 displays a sample Jupyter cell in Edit mode.

Figure A.14 Empty Jupyter Notebook cell in Edit mode

Below the Notebook’s navigation menu, you’ll find a toolbar for common shortcuts. A drop-down menu at the right end of the toolbar displays the focused cell’s type. Click the drop-down menu to reveal a list of available cell options, and choose Code or Markdown to change a cell to that type (figure A.15).

Figure A.15 Changing the type of a Jupyter Notebook cell

One of the best features of Jupyter Notebooks is its trial-and-error approach to development. We enter Python code in a Code cell and then execute it. Jupyter outputs the result below the cell. We check whether the result matches what we expect and continue the process. This approach encourages active experimentation; we’re always a keyboard press away from seeing the difference that a line of code makes.

Let’s execute some basic Python code. Enter the following mathematical expression inside the Notebook’s first cell and then click the Run button on the toolbar to execute it:

In  [1]: 1 + 1
 
Out [1]: 2

The box to the left of the code (displaying the number 1 in the preceding example) marks the cell’s execution order relative to the launch or restart of the Jupyter Notebook. You can execute the cells in any order, and you can execute the same cell multiple times.

As you read through the book, I encourage you to experiment by executing different snippets of code in your Jupyter cells. Thus, it is OK if your execution numbers do not match those in the text.

If a cell contains multiple lines of code, Jupyter will output the evaluation of the last expression. Note that Python still runs all the code in the cell; we see only the last expression.

In  [2]: 1 + 1
         3 + 2
 
Out [2]: 5

The interpreter is the software that parses your Python source code and executes it. Jupyter Notebook relies on IPython (Interactive Python), an enhanced interpreter with extra features for developer productivity. As one example, you can use the Tab key to reveal available methods and attributes on any Python object. The next example shows the available methods on a Python string. Type any string and a dot; then press Tab to see the dialog box. Figure A.16 shows an example with a string. If you’re unfamiliar with Python’s core data structures, see appendix B for a comprehensive introduction to the language.

Figure A.16 Jupyter Notebook’s autocomplete features

You can enter any amount of Python in a Code cell, but it’s best to keep a cell’s size reasonably small to improve readability and comprehension. If your logic is complex, split the operations across several cells.

You can use either of two keyboard shortcuts to execute a cell in Jupyter Notebook. Press Shift-Enter to execute a cell and move focus to the next cell, and press Ctrl-Enter to execute a cell and maintain focus on the original cell. Practice reexecuting the first two cells to see this difference in action.

Press the Esc key to activate Command mode, a management mode for the Notebook. The available operations in this mode are more global; they affect the Notebook as a whole rather than one specific cell. In this mode, keyboard characters serve as shortcuts. Here are some helpful keyboard shortcuts to use when the Notebook is in Command mode:

Keyboard shortcut

Description

Up- and down-arrow keys

Navigate through Notebook cells.

a

Create a new cell above the selected cell.

b

Create a new cell below the selected cell.

c

Copy the contents of a cell.

x

Cut the contents of a cell.

v

Paste a copied or cut cell into the cell below the selected one.

d+d

Delete a cell.

z

Reverse a deletion.

y

Change the cell type to Code.

m

Change the cell type to Markdown.

h

Show the help menu, which has a complete list of keyboard shortcuts.

Command-S (macOS) or Ctrl-S (Windows)

Save the Notebook. Note that Jupyter Notebook also has autosave functionality.

To clear everything from the Notebook’s memory, choose Kernel from the top-level menu and then choose Restart. Additional options are available to clear cell outputs and rerun all cells in the Notebook.

Let’s say that we’ve had enough fun with our Notebook for the day and decide it’s time to exit. A Notebook continues running in the background even when we close its browser tab. To close it, navigate to the Running tab on the top menu of the Jupyter launch screen, and click the Shutdown button next to the Notebook (figure A.17).

Figure A.17 Shutting down a Jupyter Notebook

After we shut down all Notebooks, we have to terminate the Jupyter Notebook application. Close the browser tab with the Jupyter application. In Terminal or Anaconda Prompt, press Ctrl+C twice to terminate the local Jupyter server.

At this point, you’re all set to start writing Python and pandas code in Jupyter. Good luck!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.169.94