Practical Python Data Visualization: A Fast Track Approach To Learning Data Visualization With Python Ashwin Pajankar Download PDF
Practical Python Data Visualization: A Fast Track Approach To Learning Data Visualization With Python Ashwin Pajankar Download PDF
com
https://textbookfull.com/product/practical-python-
data-visualization-a-fast-track-approach-to-
learning-data-visualization-with-python-ashwin-
pajankar/
https://textbookfull.com/product/gnu-octave-by-example-a-fast-and-
practical-approach-to-learning-gnu-octave-ashwin-pajankar/
textbookfull.com
https://textbookfull.com/product/matplotlib-for-python-developers-
effective-techniques-for-data-visualization-with-python-2nd-edition-
yim/
textbookfull.com
https://textbookfull.com/product/who-knew-answers-to-questions-about-
classical-music-you-never-thought-to-ask-1st-edition-robert-a-
cutietta/
textbookfull.com
Jacaranda New Concepts in Commerce NSW Australian
Curriculum Fourth Edition Stephen Chapman
https://textbookfull.com/product/jacaranda-new-concepts-in-commerce-
nsw-australian-curriculum-fourth-edition-stephen-chapman/
textbookfull.com
https://textbookfull.com/product/animals-and-human-society-in-asia-
historical-cultural-and-ethical-perspectives-rotem-kowner/
textbookfull.com
https://textbookfull.com/product/audio-education-theory-culture-and-
practice-1st-edition-daniel-walzer-editor-mariana-lopez-editor/
textbookfull.com
https://textbookfull.com/product/training-guide-configuring-advanced-
windows-server-2012-r2-services-mcsa-1st-edition-orin-thomas/
textbookfull.com
Frontiers of Cyberlearning Emerging Technologies for
Teaching and Learning J. Michael Spector
https://textbookfull.com/product/frontiers-of-cyberlearning-emerging-
technologies-for-teaching-and-learning-j-michael-spector/
textbookfull.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
v
Table of Contents
vi
Table of Contents
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.
xi
About the Technical Reviewers
xii
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
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.
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.
2
Chapter 1 Introduction to Python
• 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.
7. Readability counts.
3
Chapter 1 Introduction to Python
A
pplications of Python
Because Python is a general-purpose programming language, it has
numerous applications in the following areas:
1. Web development.
4. Software development.
5. System administration.
4
Chapter 1 Introduction to Python
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).
6
Chapter 1 Introduction to Python
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
Python 3.8.1
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
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
python3 -V
pip3 -V
which python3
which pip3
Almost all the other popular Linux distributions come with Python
preinstalled, too.
8
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
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.
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
11
Chapter 1 Introduction to Python
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.
12
Chapter 1 Introduction to Python
idle
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.
13
Random documents with unrelated
content Scribd suggests to you:
money, when all over Europe great mercantile houses were
breaking. One of the most notable characteristics of Benjamin was,
we are told, his astonishing knowledge of firms, which was not
confined merely to England, but embraced the whole money-market
in or out of England. He valued, with a certainty bordering on the
marvellous, every name on the back of a bill. In the panic year of
1790, the house only lost £50, when ruin swept away many of the
chief firms of England and abroad. At the beginning of the present
century, there was no house greater, or more universally esteemed;
and yet the end was tragic in the extreme. One morning in April,
1808, Benjamin Goldsmid hung himself in his bed-room. In 1810,
the elder brother, Abraham, in conjunction with the house of Baring,
embarked in a government loan of £14,000,000. The business
failed; the house of Baring survived the crash; but Abraham
Goldsmid shot himself when he found how true it was that riches
take to themselves wings, and fly away.
Here is a story of an alderman, extracted from Maloniana. When the
late Mr. Pitt, or Alderman Beckford, made a strong attack on the late
Sir William Baker, alderman of London, charging him with having
made an immense sum by a fraudulent contract, he got up very
quietly, and gained the House to his side by this short reply: “The
honourable gentleman is a great orator, and has made a long and
serious charge against me. I am no orator, and shall therefore only
answer it in two words—Prove it.” Having thus spoken, he sat
down; but there was something in his tone and manner that
satisfied the House the charge was a calumny.
In 1736, there was—as I dare say there is now—an old Mr. Collier in
the City. He lived in Essex, and his daughter—as is generally the
case with rich City men—soon got married. It was thus the Rev. Dr.
Taylor, of Isleworth, in 1788, described the wedding;—“Old Mr.
Collier was a very vain man, who had made his fortune in the South
Sea year: and having been originally a merchant, was fond, alter he
had retired to live upon his fortune, of a great deal of display and
parade. On his daughter’s wedding, therefore, he invited nearly fifty
persons, and got two or three capital cooks from London to prepare
a magnificent entertainment in honour of the day. When other
ceremonies had concluded, the young couple were put to bed, and
every one of the numerous assemblage came into the room to make
these congratulations to the father and mother, who sat up in bed to
receive them: ‘Madame, I wish you a very good-night. Sir, all
happiness to you, and a very good-night,’ and so on through the
whole party. My father, who hated all parade, but was forced to
submit to the old gentleman’s humour, must have been in a fine
fume; and my mother, who was then but seventeen or eighteen,
sufficiently embarrassed.” It is as well rich citizens don’t indulge in
such a display on the occasion of a marriage in the family in our
time. I don’t fancy even a Lord Mayor, however fond of antiquity,
would feel himself justified in attempting anything so ridiculous
now. But then it was the fashion for a well-bred youth to address
his father as “honoured sir,” and not as now, as “governor.”
Another money-making family was that of the Hopes, originally from
Holland. “Mr. William Hope,” says old Captain Gronow, “inherited, on
coming of age, £40,000 a-year. He exhibited, alternately, extreme
recklessness in expenditure, and the stinginess of a miser. He would
one day spend thousands of pounds on a ball or supper, and then
keep his servants for days on cold meat and stale bread. His large
fortune enabled him to give the most splendid entertainments to the
beau monde of Paris. At his balls and parties all the notables of the
day were to be seen, and no expense was spared to make them the
most sumptuous entertainments then given. It was his custom,
when the invitations were issued, not to open any letters till the
party was over, to save him the mortification of refusing those who
had not been invited.”
If we are to believe the great poet, who mostly spent his life in
London, and whose name still graces a street very much reduced
from what it was in his day, Mammon-worship must have a very bad
moral effect, for Mammon was the least erected spirit that fell from
heaven; and even there we are told—
“His looks and thoughts
Were always downward bent, admiring more
The riches of heaven’s pavement, trodden gold,
Than aught divine or holy else enjoyed
In vision beautiful.”