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

Get Practical Python Data Visualization: A Fast Track Approach To Learning Data Visualization With Python Ashwin Pajankar PDF ebook with Full Chapters Now

Data

Uploaded by

cancefiorar5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
64 views

Get Practical Python Data Visualization: A Fast Track Approach To Learning Data Visualization With Python Ashwin Pajankar PDF ebook with Full Chapters Now

Data

Uploaded by

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

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Practical Python Data Visualization: A Fast Track


Approach To Learning Data Visualization With
Python Ashwin Pajankar

https://textbookfull.com/product/practical-python-data-
visualization-a-fast-track-approach-to-learning-data-
visualization-with-python-ashwin-pajankar/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

GNU Octave by Example: A Fast and Practical Approach to


Learning GNU Octave Ashwin Pajankar

https://textbookfull.com/product/gnu-octave-by-example-a-fast-and-
practical-approach-to-learning-gnu-octave-ashwin-pajankar/

textboxfull.com

Matplotlib for Python Developers Effective techniques for


data visualization with Python 2nd Edition Yim

https://textbookfull.com/product/matplotlib-for-python-developers-
effective-techniques-for-data-visualization-with-python-2nd-edition-
yim/
textboxfull.com

Practical Data Science Cookbook Data pre processing


analysis and visualization using R and Python Prabhanjan
Tattar
https://textbookfull.com/product/practical-data-science-cookbook-data-
pre-processing-analysis-and-visualization-using-r-and-python-
prabhanjan-tattar/
textboxfull.com

Python Data Analysis: Perform data collection, data


processing, wrangling, visualization, and model building
using Python 3rd Edition Avinash Navlani
https://textbookfull.com/product/python-data-analysis-perform-data-
collection-data-processing-wrangling-visualization-and-model-building-
using-python-3rd-edition-avinash-navlani/
textboxfull.com
Data Visualization with Python and JavaScript Scrape Clean
Explore Transform Your Data 1st Edition Kyran Dale

https://textbookfull.com/product/data-visualization-with-python-and-
javascript-scrape-clean-explore-transform-your-data-1st-edition-kyran-
dale/
textboxfull.com

Python Unit Test Automation. Practical Techniques for


Python Developers and Testers 1st Edition Ashwin Pajankar

https://textbookfull.com/product/python-unit-test-automation-
practical-techniques-for-python-developers-and-testers-1st-edition-
ashwin-pajankar/
textboxfull.com

GNU Octave by Example A Fast and Practical Approach to


Learning GNU Octave 1st Edition Ashwin Pajankar Sharvani
Chandu
https://textbookfull.com/product/gnu-octave-by-example-a-fast-and-
practical-approach-to-learning-gnu-octave-1st-edition-ashwin-pajankar-
sharvani-chandu/
textboxfull.com

Learning Data Mining with Python Layton

https://textbookfull.com/product/learning-data-mining-with-python-
layton/

textboxfull.com

Learn Keras for Deep Neural Networks: A Fast-Track


Approach to Modern Deep Learning with Python 1st Edition
Jojo John Moolayil
https://textbookfull.com/product/learn-keras-for-deep-neural-networks-
a-fast-track-approach-to-modern-deep-learning-with-python-1st-edition-
jojo-john-moolayil/
textboxfull.com
Practical Python
Data Visualization
A Fast Track Approach To Learning
Data Visualization With Python

Ashwin Pajankar
Practical Python Data
Visualization
A Fast Track Approach
To Learning Data Visualization
With Python

Ashwin Pajankar
Practical Python Data Visualization: A Fast Track Approach To Learning
Data Visualization With Python
Ashwin Pajankar
Nashik, Maharashtra, India

ISBN-13 (pbk): 978-1-4842-6454-6 ISBN-13 (electronic): 978-1-4842-6455-3


https://doi.org/10.1007/978-1-4842-6455-3

Copyright © 2021 by Ashwin Pajankar


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Aditee Mirashi
Development Editor: James Markham
Coordinating Editor: Aditee Mirashi
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media 1 New York Plaza,
New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM
Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for
reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Print and eBook
Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-6454-6.
For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
I dedicate this book to Abhijit Banerjee, Nobel Laureate
economist of Indian origin
Table of Contents
About the Author���������������������������������������������������������������������������������ix

About the Technical Reviewers�����������������������������������������������������������xi


Acknowledgments�����������������������������������������������������������������������������xiii
Introduction����������������������������������������������������������������������������������������xv

Chapter 1: Introduction to Python��������������������������������������������������������1


Python Programming Language����������������������������������������������������������������������������1
History of Python���������������������������������������������������������������������������������������������2
Python Enhancement Proposals����������������������������������������������������������������������3
Applications of Python�������������������������������������������������������������������������������������4
Installing Python on Various Platforms�����������������������������������������������������������������5
Installing on a Windows Computer������������������������������������������������������������������5
Installing on Ubuntu and Debian Derivatives���������������������������������������������������8
Python Modes�������������������������������������������������������������������������������������������������������9
Interactive Mode��������������������������������������������������������������������������������������������13
Script Mode���������������������������������������������������������������������������������������������������14
Summary������������������������������������������������������������������������������������������������������������16

Chapter 2: Exploring Jupyter Notebook����������������������������������������������17


Overview of Jupyter Notebook����������������������������������������������������������������������������18
Setting up Jupyter Notebook������������������������������������������������������������������������������19
Running Code in Jupyter Notebook���������������������������������������������������������������������25
Summary������������������������������������������������������������������������������������������������������������29

v
Table of Contents

Chapter 3: Data Visualization with Leather����������������������������������������31


Running OS Commands in Jupyter Notebook�����������������������������������������������������31
Introduction to Leather���������������������������������������������������������������������������������������33
More Types of Visualizations�������������������������������������������������������������������������������37
Scales�����������������������������������������������������������������������������������������������������������������43
Styling�����������������������������������������������������������������������������������������������������������������45
Summary������������������������������������������������������������������������������������������������������������48

Chapter 4: Scientific Python Ecosystem and NumPy�������������������������49


Scientific Python Ecosystem�������������������������������������������������������������������������������50
NumPy and Ndarrays������������������������������������������������������������������������������������������51
More Than One Dimension����������������������������������������������������������������������������53
Ndarray Properties����������������������������������������������������������������������������������������������54
NumPy Constants������������������������������������������������������������������������������������������������55
Summary������������������������������������������������������������������������������������������������������������56

Chapter 5: Data Visualization with NumPy and Matplotlib�����������������57


Matplotlib������������������������������������������������������������������������������������������������������������58
Visualization with NumPy and Matplotlib������������������������������������������������������������59
Single Line Plots�������������������������������������������������������������������������������������������������64
Multiline Plots�����������������������������������������������������������������������������������������������������66
Grid, Axes, and Labels�����������������������������������������������������������������������������������������68
Colors, Styles, and Markers��������������������������������������������������������������������������������73
Summary������������������������������������������������������������������������������������������������������������79

vi
Table of Contents

Chapter 6: Visualizing Images and 3D Shapes�����������������������������������81


Visualizing the Images����������������������������������������������������������������������������������������81
Operations on Images�����������������������������������������������������������������������������������������85
3D Visualizations�������������������������������������������������������������������������������������������������93
Summary����������������������������������������������������������������������������������������������������������100

Chapter 7: Visualizing Graphs and Networks�����������������������������������101


Graphs and Networks���������������������������������������������������������������������������������������101
Graphs in Python 3��������������������������������������������������������������������������������������102
Visualizing Graphs in Python 3��������������������������������������������������������������������������105
More Types of Graphs���������������������������������������������������������������������������������������107
Assigning Custom Labels to Nodes�������������������������������������������������������������������114
Summary����������������������������������������������������������������������������������������������������������115

Chapter 8: Getting Started with Pandas�������������������������������������������117


Introduction to Pandas��������������������������������������������������������������������������������������117
Series in Pandas������������������������������������������������������������������������������������������118
Basic Operations on Series�������������������������������������������������������������������������120
Dataframes in Pandas���������������������������������������������������������������������������������������121
Reading Data Stored in CSV Format������������������������������������������������������������127
Visualizing with Pandas������������������������������������������������������������������������������������128
Summary����������������������������������������������������������������������������������������������������������136

Chapter 9: Working with COVID-19 Data������������������������������������������137


The COVID-19 Pandemic and the Data Set�������������������������������������������������������137
Data Sources for COVID-19 Data�����������������������������������������������������������������138
Visualizing the COVID-19 Data��������������������������������������������������������������������������142
Summary����������������������������������������������������������������������������������������������������������155

Index�������������������������������������������������������������������������������������������������157

vii
About the Author
Ashwin Pajankar holds a Master of Technology from IIIT Hyderabad,
and he has more than 25 years of programming experience. He started
his journey in programming and electronics at the tender age of
seven with the BASIC programming language and is now proficient in
Assembly programming, C, C++, Java, Shell scripting, and Python. His
other technical experience includes single-board computers such as
Raspberry Pi and Banana Pro, and Arduino. He is currently a freelance
online instructor teaching programming bootcamps to more than 60,000
students from tech companies and colleges. His YouTube channel has an
audience of 10,000 subscribers and he has published more than 15 books
on programming and electronics with many additional international
publications.

ix
About the Technical Reviewers
Lentin Joseph is an author, roboticist, and
robotics entrepreneur from India. He runs
robotics software company Qbotics Labs
in Kochi and Kerala. He has ten years of
experience in the robotics domain, primarily
in Robot Operating System (ROS), OpenCV,
and PCL. He has authored eight books on ROS,
including Learning Robotics Using Python,
Mastering ROS for Robotics Programming, ROS
Robotics Projects, and Robot Operating System for Absolute Beginners. He
has pursued his master’s degress in robotics and automation in India and
also worked at the Robotics Institute at Carnegie Mellon University. He has
also been a TEDx speaker.

Aarthi Elumalai is a programmer, educator,


entrepreneur, and innovator. She has a
Bachelor of Engineering degree in computer
science from Anna University, Chennai,
India. She has launched a dozen web apps,
plug-ins, and software applications that are
being used by thousands of customers online.
She has more than 15 years of experience in
programming. She is the founder of DigiFisk,
an e-learning platform that has more than 70,000 students worldwide.

xi
About the Technical Reviewers

Her courses are well-received by the masses, and her unique,


project-based approach is a refreshing change for many. She teaches
the complex world of programming by using practical exercises and
puzzles along the way. Her courses and books always come with
hands-on training in creating real-­world projects so her students are
better equipped for the real world.

xii
Acknowledgments
I want to express my gratitude to all of the technical reviewers for helping
me to make this book better. I would also like to express my gratitude to the
team from Apress. Aditee Mirashi helped us to coordinate the entire book
process. I am also grateful to Celestin Suresh for giving me the opportunity
to write this book.

xiii
Introduction
I have been working with the Python programming language for more than
15 years now. I have used it for a variety of tasks like automation, graphics,
Internet of Things (IoT), and data science. I have found that it is a very
good tool for generating scientific and data-driven business visualizations.
It takes fewer lines of code to generate visualizations with Python. Python
is capable of fetching data from various type of sources. Combining this
feature with various third-party visualization libraries makes Python the
perfect tool for various types of visualization requirements.
This book covers the basics of Python, including setup and various
modes, and many visualization libraries. I have also made a modest
attempt to visualize real-life data related to the ongoing COVID-19
pandemic.
I encourage readers to read all of the material and not to skip anything,
even if you are familiar with the particular topic. I have written this book
in such a way that every topic and demonstration builds confidence in the
reader for the next topic. This truly is a step-by-step guide for beginners
and experts alike.
After reading this book, you will be empowered by the knowledge of
data visualization with Python and will be able to apply this knowledge
in real-life projects at your workplace. It will also instill confidence in you
to explore more libraries for data visualization in Python, as most of the
support the scientific Python ecosystem and NumPy library discussed in
detail in this book.
I hope that readers of this book will enjoy reading it and following the
demonstrations as much as I enjoyed writing it.

xv
CHAPTER 1

Introduction to
Python
I welcome you all to the exciting journey of learning data visualization with
Python 3. This chapter provides details to get you started with the Python
programming language, including its history, features, and applications.
This chapter is focused on general information about Python 3 and its
installation on various popular operating system (OS) platforms, such as
Microsoft Windows, Ubuntu, and Raspberry Pi Raspbian. We will be writing
a few basic Python programs and learn how to execute them on various
platforms. Here is the list of topics that we will cover in this chapter.

• Python programming language

• Installing Python on various platforms


• Python modes

After completing this chapter, you should be comfortable with


installation and usage of Python 3 programming language in various modes.

Python Programming Language


Python 3 is a high-level, interpreted, general-purpose programming
language. This section provides a general discussion about the Python
programming language and its philosophy.

© Ashwin Pajankar 2021 1


A. Pajankar, Practical Python Data Visualization,
https://doi.org/10.1007/978-1-4842-6455-3_1
Chapter 1 Introduction to Python

History of Python
Python is a successor to the ABC programming language, which itself
was inspired by the ALGOL 68 and SETL programming languages. It was
created by Guido Van Rossum as a personal side project during vacations
in the late 1980s while he was working at CWI Centrum Wiskunde &
Informatica in the Netherlands. From the initial release of Python through
July 2018, Van Rossum was the lead developer and Benevolent Dictator
for Life for this project. Since then, he has gone into a state of permanent
vacation and now works on a steering committee for Python. The following
timeline details the important milestones in Python’s release.

• February 1991: Van Rossum published the code


(labeled version 0.9.0) to alt.sources.

• January 1994: Version 1.0 was released.

• October 2000: Python 2.0 was released.

• December 2006: Python 3.0 was released.

• December 2019: Python 2.x was officially retired


and is no longer supported by the Python Software
Foundation.

Python 2.x versions are retired and no longer supported. In addition,


Python 3 is not backward compatible with Python 2. Python 3 is the latest
and currently supported version the language. We therefore use Python
3 throughout the book to demonstrate programs for data visualization.
Unless explicitly mentioned, Python denotes Python 3 throughout this
book.

2
Chapter 1 Introduction to Python

Python Enhancement Proposals


To steer the development, maintenance, and support of Python,
the Python leadership team came up with the concept of Python
Enhancement Proposals (PEPs). These are the primary mechanism for
suggesting new features and fixing issues in Python project. You can read
more about the PEPs at the following URLs:

• https://www.python.org/dev/peps/

• https://www.python.org/dev/peps/pep-0001/

P
 hilosophy of Python
The philosophy of Python is detailed in PEP20, known as The Zen of
Python, available at https://www.python.org/dev/peps/pep-0020/. Here
are some of the points from that PEP.

1. Beautiful is better than ugly.

2. Explicit is better than implicit.

3. Simple is better than complex.

4. Complex is better than complicated.

5. Flat is better than nested.

6. Sparse is better than dense.

7. Readability counts.

8. Special cases aren’t special enough to break the rules.

9. Although practicality beats purity.

10. Errors should never pass silently.

11. Unless explicitly silenced.

12. In the face of ambiguity, refuse the temptation to guess.

3
Chapter 1 Introduction to Python

13. There should be one—and preferably only


one—obvious way to do it.

14. Although that way may not be obvious at first unless


you’re Dutch.

15. Now is better than never.

16. Although never is often better than *right* now.

17. If the implementation is hard to explain, it’s a bad


idea.

18. If the implementation is easy to explain, it may be a


good idea.

19. Namespaces are one honking great idea—let’s do


more of those!

These are among the general philosophical guidelines that influenced


the development of the Python programming language and continue to
do so.

A
 pplications of Python
Because Python is a general-purpose programming language, it has
numerous applications in the following areas:

1. Web development.

2. Graphical user interface (GUI) development.

3. Scientific and numerical computing.

4. Software development.

5. System administration.

Case studies of Python for various projects are available at ­https://


www.python.org/success-stories/.

4
Chapter 1 Introduction to Python

Installing Python on Various Platforms


A Python implementation is a program or an environment that supports
the execution of programs written in Python. The original implementation
created by Van Rossum is known as CPython and serves as a reference
implementation. Throughout the book, we use CPython. It is available on
the Python website and we will learn how to install it in this section.
I prefer to write Python programs on a Windows computer or a Raspberry
Pi computer with Raspberry Pi OS. Let us learn how to install Python on
both of these platforms.

Installing on a Windows Computer


Visit the Python 3 download page located at https://www.python.org/
downloads/ and download the Python 3 setup file for your computer. It will
automatically detect the OS on your computer and show the appropriate
downloadable file, as displayed in Figure 1-1.

Figure 1-1. Python Project home page with download options

5
Chapter 1 Introduction to Python

Run the setup file to install Python 3. During installation, select the
check box related to adding Python 3 to the PATH variable (Figure 1-2).

Figure 1-2. Python Installation Wizard

Click Customize Installation, which provides the customization


options shown in Figure 1-3.

6
Chapter 1 Introduction to Python

Figure 1-3. Python installation options

Select all the check boxes and click Next to continue the setup.
Complete the setup. The name of the binary executable program for
Python is python on Windows OS. Once installation is finished, run the
following command at the Windows command prompt cmd.

python -V

It will return the version of Python 3 as follows:

Python 3.8.1

We can also check the version of pip3 as follows:

pip3 -V

pip stands for Pip installs Python or Pip installs Packages; its name is
a recursive acronym. It is a package manager for the Python programming
language. We can install the other needed Python libraries for our
demonstrations using the pip utility.

7
Chapter 1 Introduction to Python

To determine the exact locations of Python, you can run the where
command as follows:

where python

It returns the following result:

C:\Users\Ashwin\AppData\Local\Programs\Python\Python38-32\
python.exe

Similarly, we can learn the location of the pip3 utility by running the
following command:

where pip3

Installing on Ubuntu and Debian Derivatives


Debian is a popular distribution. Ubuntu Linux and Raspberry Pi OS are
other popular distributions based on Debian. Python 3 and pip3 come
preinstalled on all the Debian distributions and derivatives like Ubuntu
or Raspberry Pi OS, so we do not have to install them separately. I use
Raspberry Pi OS on a Raspberry Pi 4B with 4 GB RAM. Both the major
Python versions, Python 2 and Python 3, come preinstalled on Debian
derivatives. Their executables are named python and python3 for Python 2
and Python 3, respectively. We must use python3 for our demonstrations.
To determine the versions and locations of the needed binary executable
files, run the following commands one by one.

python3 -V
pip3 -V
which python3
which pip3

Almost all the other popular Linux distributions come with Python
preinstalled, too.

8
Chapter 1 Introduction to Python

P
 ython Modes
Python has various modes that we will discuss one by one. First, though, we
need to learn about the integrated development and learning environment
(IDLE). This is an integrated development environment (IDE) developed
by the Python Software Foundation for Python programming. When we install
the CPython implementation of Python 3 on Windows, IDLE is also installed.
We can launch it on the Windows OS in various ways. The first way is to search
for it in the Windows Search bar by typing IDLE as shown in Figure 1-4.

Figure 1-4. Python IDLE on Windows


9
Chapter 1 Introduction to Python

The other way is to launch it from the command prompt (cmd) by


running the following command:

idle

This will launch the window shown in Figure 1-5.

Figure 1-5. Python IDLE

Before we proceed, we need to configure it to be easy to read. We


can change the font by selecting Options ➤ Configure IDLE as shown in
Figure 1-6.

Figure 1-6. Configuring IDLE

The window shown in Figure 1-7 opens. There you can change the font
and size of the characters in IDLE.

10
Chapter 1 Introduction to Python

Figure 1-7. IDLE configuration

11
Chapter 1 Introduction to Python

Adjust the font settings according to your own preferences.


All the Linux distributions might not come with IDLE preinstalled. We
can install it on Debian and its derivatives (Ubuntu and Raspberry Pi OS)
by running the following commands in sequence.

sudo apt-get update


sudo apt-get install idle3

Once the installation is complete, we can find IDLE on the menu (in
this case the Raspberry Pi OS menu) as shown in Figure 1-8.

Figure 1-8. IDLE on the Raspberry Pi OS menu

12
Chapter 1 Introduction to Python

We can also launch IDLE on Linux by running the following command:

idle

Now let us discuss the various Python modes.

I nteractive Mode
Python’s interactive mode is a command-line type of shell that executes
the current statement and gives immediate feedback in the console. It runs
the previously fed statements in active memory. As new statements are fed
into and executed by the interpreter, the code is evaluated. When we open
IDLE, we see a command-line prompt that is Python’s interactive mode.
Let’s look at a simple example. Let’s type in the customary Hello World
program in the interactive prompt as follows:

print('Hello World!')

Press Enter to feed the line to the interpreter and execute it. Figure 1-9
presents a screenshot of the output.

Figure 1-9. Python interactive mode on IDLE

13
Chapter 1 Introduction to Python

We can launch Python interactive mode from the command prompt,


too. At the Linux command prompt (e.g., lxterminal), we must run the
command python3 and at the Windows command prompt cmd, we have
to run the command python to launch it. Figure 1-10 is a screenshot of the
interactive mode at the Windows command prompt.

Figure 1-10. Python interactive mode at the Windows command


prompt

Script Mode
We can write a Python program and save it to disk. Then we can launch it
in multiple ways. This is known as script mode. Let us demonstrate it in
IDLE. We can use any text editor to write the Python program, but because
IDLE is an IDE, it is convenient to write and run the Python programs with
IDLE. Let’s look at that first. In IDLE, select File ➤ New File to create a
blank new file. Add the following code to that:

print('Hello World!')

Save it with the name prog01.py on the disk (Figure 1-11).

14
Chapter 1 Introduction to Python

Figure 1-11. A Python program in the IDLE code editor

On the menu, click Run ➤ Run Module. This executes the program at
the IDLE’s prompt, as shown in Figure 1-12.

Figure 1-12. A Python program under execution at the IDLE


prompt

We can even launch the program with Python’s interpreter at the


command prompt of the OS, too. Open the command prompt of the OS
and navigate to the directory where the program is stored. At the Windows
command prompt, run the following command:

python prog01.py

On the Linux terminal, we must run the following command prompt:

python3 prog01.py

Then the interpreter will run the program at the command prompt and
the output (if any) will appear there.

15
Chapter 1 Introduction to Python

In Linux, there is another way we can run the program without


explicitly using the interpreter. We must add a shebang line to the
beginning of the code file. For example, our code file looks like this:

#!/usr/bin/python3
print('Hello World!')

The first line of this code is known as a shebang line. It tells the shell
what interpreter to use and its location. Run the following command to
change the file permission to make it executable for the owner as follows:

chmod 755 prog01.py

Then we can directly launch our Python program file like any other
executable with ./ as follows:

./prog01.py

The shell will execute the program and print the output to the terminal.
Note that this is applicable only for Unix-like systems (Linux and macOS)
as they support executing programs like this. We will learn more about the
Python programming as and when we need from the next chapter onward.

Summary
This chapter started with the basics of the Python programming language.
You learned how to write basic Python programs and execute them in
various ways. You learned to work with Python on various OSs, including
Windows and Linux. You also learned about various Python modes and
how to launch them from the command prompts of various OSs.
In the next chapter, we will learn how to install Jupyter Notebook and
take a brief tour of Jupyter Notebook.

16
CHAPTER 2

Exploring Jupyter
Notebook
In Chapter 1, we acquainted ourselves with Python and learned how to
write a very simple program with Python. We also saw how to use Python
in both interactive mode and script mode. In this chapter, we explore
Jupyter Notebook. In Chapter 1 we saw that interactive mode offers us
the immediate feedback of Python statements. We will continue using
the interactive mode of Python throughout the book almost all of the
demonstrations. However, rather than using Python’s built-in interactive
mode with an interpreter, we will use another and much better tool known
as the Jupyter tool. This entire chapter is dedicated to this topic.
You will learn about the following topics in this chapter:

• Overview of Jupyter Notebook.

• Setting up Jupyter Notebook.

• Running code in Jupyter Notebook.

After you complete this chapter, you should be comfortable with


Python programming using Jupyter Notebook.

© Ashwin Pajankar 2021 17


A. Pajankar, Practical Python Data Visualization,
https://doi.org/10.1007/978-1-4842-6455-3_2
Another Random Scribd Document
with Unrelated Content
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like