Practical Python Data Visualization: A Fast Track Approach To Learning Data Visualization With Python Ashwin Pajankar - The ebook is available for online reading or easy download
Practical Python Data Visualization: A Fast Track Approach To Learning Data Visualization With Python Ashwin Pajankar - The ebook is available for online reading or easy download
com
https://textbookfull.com/product/practical-python-data-
visualization-a-fast-track-approach-to-learning-data-
visualization-with-python-ashwin-pajankar/
OR CLICK HERE
DOWLOAD EBOOK
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/data-visualization-with-python-and-
javascript-scrape-clean-explore-transform-your-data-1st-edition-kyran-
dale/
textbookfull.com
https://textbookfull.com/product/python-unit-test-automation-
practical-techniques-for-python-developers-and-testers-1st-edition-
ashwin-pajankar/
textbookfull.com
https://textbookfull.com/product/learning-data-mining-with-python-
layton/
textbookfull.com
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
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
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
Chapter 1 Introduction to Python
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!')
14
Chapter 1 Introduction to Python
On the menu, click Run ➤ Run Module. This executes the program at
the IDLE’s prompt, as shown in Figure 1-12.
python prog01.py
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
#!/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:
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:
— Suvaitseeko neiti?
*****
*****
4.
OLUT-TUPA BURGHOF.
— Hesputei!
Kun urhokas kapteeni sitten oli ottanut riittävän monta näitä roosa
täräyksiä, joita ystävällinen muti päätään pudistellen antoi hänelle
velaksikin, ei hän enää ollenkaan pysynyt tuolillaan, vaan alkoi
notkuvin polvin, perin hiljaa ja sammuneen näköisenä hiipiä ympäri
huonetta, ihmeen taitavasti ja läikyttämättä kantaen lasiaan ja tavan
takaa hokien:
*****
*****
Vai niin. Sen takia oli kaikki mennyt myttyyn, että me olimme
lörpötelleet, me, joista vain muutamat osasivat saksaa. Ja me
olimme juoneet itsemme raivoiksi, vaikka yksikään meistä ei ollut
esiintynyt ainakaan niin humalassa, että olisi puhunut
sopimattomia… Miksei meitä päästetty rintamalle, mistä meidät oli
tänne kutsuttu, takaisin pataljoonaan, jonka kirjoista meidät oli
pyyhitty pois? Nyt meidät komennettiin leirille jatkamaan
harjoituksia, joihin luulimme jo pystyvämme. Tosin huomautettiin
ikäänkuin salaa, että yritystämme ei vielä oltu kokonaan hyljätty, ja
että meidän tuli odottaa suotuisampia aikoja, mutta kuka siihen enää
uskoi. —
5.
MÜNSTERIN LEIRILLÄ.
Pataljoonamme reservi-joukko, joka koko ajan oli ollut
Lockstedtissä, ja josta rintamalle silloin tällöin oli tuotu
täydennysryhmiä, oli vastikään siirretty Münsterin leirille, joka sijaitsi
samannimisen kaupungin lähettyvillä. Joukko ei ollut suuri. Siihen
kuuluivat ainoastaan ne miehet, jotka vasta viime-aikoina olivat
tulleet Suomesta ja joiden siis oli saatava sotilaskasvatus ennen
rintamalle lähtöä. Sitäpaitsi vietiin tänne kaikki sairaaloista päässeet
haavoittuneet ja sairaat, joita vähitellen opetettiin uudelleen
tottumaan sotilaselämän rasituksiin, ja kaikki ne, jotka olivat liian
heikkoja voidakseen menestyksellä toimia pataljoonassa. Joukko,
jota johti ystävällinen ja miellyttävä hauptmanni Aubert, oli jaettu
kahteen pieneen komppaniaan. Kuri ei ollut likimainkaan sellainen
kuin meidän aikanamme Lockstedtissa. Harjoiteltiin paljon
vähemmän, tuvat eivät olleet läheskään niin siistit ja niin hyvässä
järjestyksessä, ja monesti nukuttiin aamulla vielä kauan sen jälkeen
kuin päivystäjä oli huutanut ylös — seikka, jota ennen vanhaan ei
voinut kuvitellakaan. Mutta ruoka oli sensijaan perin huonoa. Aina
vain lanttusoppaa, lihattomina päivinä lanttua, suolaa ja vettä,
muulloin jokunen rasvan muru lisäksi. Ja sunnuntaina saatiin
hapankaali-keittoa, jota emme voineet syödä senkään vertaa.
— Ymmärrän.
— Ei, ei lentokoneella.
— No vedenalaisella sitten.
*****
Jos pyytäjä ilkeää olla itsepintainen, voi hän kenties saada voitakin
palasen. Kaikesta tästä hyvästä suorittaa hän pienen maksun, joka
kuitenkin kovasti koettelee hänen ohutta pussiaan. —
5.
SUOMEEN.
— Olemme saksalaisia.
— Nimenne?
— Minnekä te matkustatte?
— Ruotsiin.
— Passi?
— Ei ole.
— Ei.
— Kuinka niin?
— Juuri niin.
— Olemme kyllä.
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.
textbookfull.com