Data Analysis From Scratch With Python Peters Morgan
Data Analysis From Scratch With Python Peters Morgan
com
https://textbookfull.com/product/data-analysis-from-scratch-
with-python-peters-morgan/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/data-science-from-scratch-first-
principles-with-python-2nd-edition-joel-grus/
textboxfull.com
https://textbookfull.com/product/data-science-from-scratch-first-
principles-with-python-2nd-edition-grus-joel/
textboxfull.com
https://textbookfull.com/product/data-analysis-with-python-and-
pyspark-meap-v07-jonathan-rioux/
textboxfull.com
https://textbookfull.com/product/python-for-data-analysis-data-
wrangling-with-pandas-numpy-and-ipython-wes-mckinney/
textboxfull.com
https://textbookfull.com/product/python-for-data-analysis-data-
wrangling-with-pandas-numpy-and-jupyter-3rd-edition-wes-mckinney/
textboxfull.com
https://textbookfull.com/product/learning-data-mining-with-python-
layton/
textboxfull.com
https://textbookfull.com/product/web-scraping-with-python-data-
extraction-from-the-modern-web-3rd-edition-mitchell/
textboxfull.com
D ATA A N A LY S I S F R O M S C R AT C H W I T H P Y T H O N
Step By Step Guide
Peters Morgan
How to contact us
If you find any damage, editing issues or any other issues in this book contain
please immediately notify our customer service by email at:
[email protected]
ISBN-13: 978-1721942817
ISBN-10: 1721942815
The contents of this book may not be reproduced, duplicated or transmitted without the direct written
permission of the author.
Under no circumstances will any legal responsibility or blame be held against the publisher for any
reparation, damages, or monetary loss due to the information herein, either directly or indirectly.
Legal Notice:
You cannot amend, distribute, sell, use, quote or paraphrase any part or the content within this book without
the consent of the author.
Disclaimer Notice:
Please note the information contained within this document is for educational and entertainment purposes
only. No warranties of any kind are expressed or implied. Readers acknowledge that the author is not
engaging in the rendering of legal, financial, medical or professional advice. Please consult a licensed
professional before attempting any techniques outlined in this book.
By reading this document, the reader agrees that under no circumstances is the author responsible for any
losses, direct or indirect, which are incurred as a result of the use of information contained within this
document, including, but not limited to, errors, omissions, or inaccuracies.
Thank you !
Introduction
Why read on? First, you’ll learn how to use Python in data analysis (which is a
bit cooler and a bit more advanced than using Microsoft Excel). Second, you’ll
also learn how to gain the mindset of a real data analyst (computational
thinking).
More importantly, you’ll learn how Python and machine learning applies to real
world problems (business, science, market research, technology, manufacturing,
retail, financial). We’ll provide several examples on how modern methods of
data analysis fit in with approaching and solving modern problems.
This is important because the massive influx of data provides us with more
opportunities to gain insights and make an impact in almost any field. This
recent phenomenon also provides new challenges that require new technologies
and approaches. In addition, this also requires new skills and mindsets to
successfully navigate through the challenges and successfully tap the fullest
potential of the opportunities being presented to us.
For now, forget about getting the “sexiest job of the 21st century” (data scientist,
machine learning engineer, etc.). Forget about the fears about artificial
intelligence eradicating jobs and the entire human race. This is all about learning
(in the truest sense of the word) and solving real world problems.
We are here to create solutions and take advantage of new technologies to make
better decisions and hopefully make our lives easier. And this starts at building a
strong foundation so we can better face the challenges and master advanced
concepts.
2. Why Choose Python for Data Science & Machine Learning
Python is said to be a simple, clear and intuitive programming language. That’s
why many engineers and scientists choose Python for many scientific and
numeric applications. Perhaps they prefer getting into the core task quickly (e.g.
finding out the effect or correlation of a variable with an output) instead of
spending hundreds of hours learning the nuances of a “complex” programming
language.
This allows scientists, engineers, researchers and analysts to get into the project
more quickly, thereby gaining valuable insights in the least amount of time and
resources. It doesn’t mean though that Python is perfect and the ideal
programming language on where to do data analysis and machine learning.
Other languages such as R may have advantages and features Python has not.
But still, Python is a good starting point and you may get a better understanding
of data analysis if you use it for your study and future projects.
Python vs R
You might have already encountered this in Stack Overflow, Reddit, Quora, and
other forums and websites. You might have also searched for other programming
languages because after all, learning Python or R (or any other programming
language) requires several weeks and months. It’s a huge time investment and
you don’t want to make a mistake.
To get this out of the way, just start with Python because the general skills and
concepts are easily transferable to other languages. Well, in some cases you
might have to adopt an entirely new way of thinking. But in general, knowing
how to use Python in data analysis will bring you a long way towards solving
many interesting problems.
Many say that R is specifically designed for statisticians (especially when it
comes to easy and strong data visualization capabilities). It’s also relatively easy
to learn especially if you’ll be using it mainly for data analysis. On the other
hand, Python is somewhat flexible because it goes beyond data analysis. Many
data scientists and machine learning practitioners may have chosen Python
because the code they wrote can be integrated into a live and dynamic web
application.
Although it’s all debatable, Python is still a popular choice especially among
beginners or anyone who wants to get their feet wet fast with data analysis and
machine learning. It’s relatively easy to learn and you can dive into full time
programming later on if you decide this suits you more.
Widespread Use of Python in Data Analysis
There are now many packages and tools that make the use of Python in data
analysis and machine learning much easier. TensorFlow (from Google), Theano,
scikit-learn, numpy, and pandas are just some of the things that make data
science faster and easier.
Also, university graduates can quickly get into data science because many
universities now teach introductory computer science using Python as the main
programming language. The shift from computer programming and software
development can occur quickly because many people already have the right
foundations to start learning and applying programming to real world data
challenges.
Another reason for Python’s widespread use is there are countless resources that
will tell you how to do almost anything. If you have any question, it’s very likely
that someone else has already asked that and another that solved it for you
(Google and Stack Overflow are your friends). This makes Python even more
popular because of the availability of resources online.
Clarity
Due to the ease of learning and using Python (partly due to the clarity of its
syntax), professionals are able to focus on the more important aspects of their
projects and problems. For example, they could just use numpy, scikit-learn, and
TensorFlow to quickly gain insights instead of building everything from scratch.
This provides another level of clarity because professionals can focus more on
the nature of the problem and its implications. They could also come up with
more efficient ways of dealing with the problem instead of getting buried with
the ton of info a certain programming language presents.
The focus should always be on the problem and the opportunities it might
introduce. It only takes one breakthrough to change our entire way of thinking
about a certain challenge and Python might be able to help accomplish that
because of its clarity and ease.
3. Prerequisites & Reminders
Python & Programming Knowledge
By now you should understand the Python syntax including things about
variables, comparison operators, Boolean operators, functions, loops, and lists.
You don’t have to be an expert but it really helps to have the essential knowledge
so the rest becomes smoother.
You don’t have to make it complicated because programming is only about
telling the computer what needs to be done. The computer should then be able to
understand and successfully execute your instructions. You might just need to
write few lines of code (or modify existing ones a bit) to suit your application.
Also, many of the things that you’ll do in Python for data analysis are already
routine or pre-built for you. In many cases you might just have to copy and
execute the code (with a few modifications). But don’t get lazy because
understanding Python and programming is still essential. This way, you can spot
and troubleshoot problems in case an error message appears. This will also give
you confidence because you know how something works.
Installation & Setup
If you want to follow along with our code and execution, you should have
Anaconda downloaded and installed in your computer. It’s free and available for
Windows, macOS, and Linux. To download and install, go to
https://www.anaconda.com/download/ and follow the succeeding instructions
from there.
The tool we’ll be mostly using is Jupyter Notebook (already comes with
Anaconda installation). It’s literally a notebook wherein you can type and
execute your code as well as add text and notes (which is why many online
instructors use it).
If you’ve successfully installed Anaconda, you should be able to launch
Anaconda Prompt and type jupyter notebook on the blinking underscore. This
will then launch Jupyter Notebook using your default browser. You can then
create a new notebook (or edit it later) and run the code for outputs and
visualizations (graphs, histograms, etc.).
These are convenient tools you can use to make studying and analyzing easier
and faster. This also makes it easier to know which went wrong and how to fix
them (there are easy to understand error messages in case you mess up).
Is Mathematical Expertise Necessary?
Data analysis often means working with numbers and extracting valuable
insights from them. But do you really have to be expert on numbers and
mathematics?
Successful data analysis using Python often requires having decent skills and
knowledge in math, programming, and the domain you’re working on. This
means you don’t have to be an expert in any of them (unless you’re planning to
present a paper at international scientific conferences).
Don’t let many “experts” fool you because many of them are fakes or just plain
inexperienced. What you need to know is what’s the next thing to do so you can
successfully finish your projects. You won’t be an expert in anything after you
read all the chapters here. But this is enough to give you a better understanding
about Python and data analysis.
Back to mathematical expertise. It’s very likely you’re already familiar with
mean, standard deviation, and other common terms in statistics. While going
deeper into data analysis you might encounter calculus and linear algebra. If you
have the time and interest to study them, you can always do anytime or later.
This may or may not give you an edge on the particular data analysis project
you’re working on.
Again, it’s about solving problems. The focus should be on how to take a
challenge and successfully overcome it. This applies to all fields especially in
business and science. Don’t let the hype or myths to distract you. Focus on the
core concepts and you’ll do fine.
4. Python Quick Review
Here’s a quick Python review you can use as reference. If you’re stuck or need
help with something, you can always use Google or Stack Overflow.
To have Python (and other data analysis tools and packages) in your computer,
download and install Anaconda.
Python Data Types are strings (“You are awesome.”), integers (-3, 0, 1), and
floats (3.0, 12.5, 7.77).
You can do mathematical operations in Python such as: 3 + 3
print(3+3) 7 -1
5*2
20 / 5
9 % 2 #modulo operation, returns the remainder of the division 2 ** 3 #exponentiation, 2 to the 3rd
power Assigning values to variables: myName = “Thor”
x=5
y=6
print(x + y) #result is 11
print(x*3) #result is 15
hobby = “programming”
print('Hi, my name is ' + myname + ' and my age is ' + str(age) + '. Anyway, my hobby is ' + hobby +
'.') Result is Hi, my name is Thon and my age is 25. Anyway, my hobby is programming.
If, Elif, and Else Statements (for Flow Control) print(“What’s your email?”)
myEmail = input()
print(“Type in your password.”)
typedPassword = input()
if typedPassword == savedPassword:
print(“Congratulations! You’re now logged in.”)
else:
print(“Your password is incorrect. Please try again.”)
total = 0
for num in range(101):
total = total + num
print(total)
all_reviews = [5, 5, 4, 4, 5, 3, 2, 5, 3, 2, 5, 4, 3, 1, 1, 2, 3, 5, 5]
positive_reviews = []
for i in all_reviews:
if i > 3:
print('Pass')
positive_reviews.append(i)
else:
print('Fail')
print(positive_reviews)
print(len(positive_reviews))
ratio_positive = len(positive_reviews) / len(all_reviews)
print('Percentage of positive reviews: ')
print(ratio_positive * 100)
add_numbers(5,10)
add_numbers(35,55)
def even_check(num):
if num % 2 == 0:
print('Number is even.')
else:
print('Hmm, it is odd.')
even_check(50)
even_check(51)
Lists my_list = [‘eggs’, ‘ham’, ‘bacon’] #list with strings colours = [‘red’,
‘green’, ‘blue’]
cousin_ages = [33, 35, 42] #list with integers mixed_list = [3.14, ‘circle’, ‘eggs’, 500] #list with integers
and strings #Working with lists colours = [‘red’, ‘blue’, ‘green’]
colours[0] #indexing starts at 0, so it returns first item in the list which is ‘red’
print(len(my_list)) #returns 10
#taking random indices to split the dataset into train and test
test_ids = np.random.permutation(len(x))
x_train = x[test_ids[:-10]]
x_test = x[test_ids[-10:]]
y_train = y[test_ids[:-10]]
y_test = y[test_ids[-10:]]
LE GÉNÉRAL TRÉPOW
« Il peut avoir de soixante à soixante-cinq ans. Il est
laid de figure, sa moustache grisonnante coupée ras au-
dessus de la lèvre supérieure lui donne, avec ses pointes
hérissées, un faux air de chat-tigre guettant une proie. Le
front est étroit, déprimé, le profil quelque peu anguleux ;
l’âge s’annonce surtout par les plis des joues,
insuffisamment dissimulés par des favoris qui s’arrêtent à
moitié du visage.
» Après l’avoir vu une seule fois, on peut juger
l’homme : c’est le gendarme personnifié ; non pas le
Pandore de la chanson, rigoureux et naïf à la fois,
aimable avec le prisonnier à qui il vient de serrer les
pouces, mais le gendarme quelque peu bourreau bien
plus au service de l’arbitraire politique que du Code. Les
cheveux coupés en brosse achèvent le caractère de cette
physionomie.
» Il ne connaît d’autre costume que son uniforme : un
pantalon bleu à large bande d’or et une tunique verte
chamarrée de décorations qui emprisonne étroitement
son buste court et trapu. Sur cette tunique, le général
jette, quand il sort, l’hiver, dans sa troïka, dont le triple
attelage peut valoir 1,500 louis, l’immense manteau
militaire à triple collet qui pourrait abriter une famille de
saltimbanques ; dans son cabinet, quand l’ouvrage le
presse et que les calorifères entretiennent une
température d’étuve, Trépow lâche un à un les boutons
de sa tunique qui s’ouvre alors sur un gilet blanc. Il court
ainsi de son cabinet de travail à la galerie d’audience où
se tiennent les solliciteurs.
» Quiconque désire parler au gouverneur, soit pour
présenter une pétition soit pour un visa, soit pour une
demande quelconque, soit comme la célèbre acquittée,
pour décharger un revolver à bout portant, peut se
présenter de une heure à trois. On fait attendre les
solliciteurs de peu de mine dans une sorte de vestibule ;
quant aux militaires, aux dames et aux visiteurs biens
vêtus, on les introduit dans cette galerie ornée de statues
et de tableaux d’une assez mince valeur artistique. Cette
pièce reçoit le jour par de nombreuses fenêtres qui
donnent sur un des nombreux canaux qui coupent en
tous sens la ville de Pierre le Grand et de Catherine.
» Personne, à moins de grandes exceptions, n’est
admis dans le cabinet du général, ce cabinet qui recèle
assez de mystères pour approvisionner une douzaine de
romanciers.
» Le général arrive dans la galerie. Il va d’un des
solliciteurs à l’autre, toujours rogue, bref et dur même
quand il accorde ce qu’on lui demande.
» On sent, dans chacune de ses paroles, dans chacun
de ses gestes, la conviction qu’il possède d’être, lui,
représentant de l’autorité, à mille coudées au-dessus du
vulgaire. Le général Trépow, armé d’un pouvoir immense,
ne dépendant que de l’empereur, professe pour son
autorité un véritable culte ; il se considère comme une
sorte de divinité vers laquelle il n’est permis d’élever que
des regards suppliants et humbles.
» Avec les étrangers, il est vrai, il change d’allures, il
craint de laisser percer le Tartare, au besoin il saura,
pendant une audience d’un quart d’heure, faire preuve
d’une politesse raffinée ou affecter une sorte de
camaraderie brusque et enjouée. Alors le visiteur se retire
enchanté en disant en lui-même : « Quel brave homme
que ce Trépow, quelle bonhomie ! quelle franchise, etc. »
Et six mois plus tard le même visiteur tombe de son haut
en apprenant que ce bonhomme si rond, si jovial, est un
geôlier de mélodrame et qu’il fait fouetter les femmes. Il
faut, d’ailleurs, se méfier un peu des effusions
humanitaires et libérales de MM. les généraux russes. J’en
sais quelque chose.
» Pendant la dernière campagne, je fus présenté, dans
une des villes prises par les Russes après le passage du
Danube, au général commandant la place. L’Excellence
me combla littéralement d’attentions et de politesses, en
proclamant la joie qu’elle éprouvait de recevoir le
correspondant d’un journal libéral. Elle me raconta sa
biographie et insista surtout sur ce point que ses idées
avancées lui avaient valu une disgrâce prolongée, — peu
s’en fallut qu’on ne l’envoyât en Sibérie. Peu de jours plus
tard, j’appris que mon pseudo-martyr de la liberté avait
fonctionné en Lithuanie comme aide de camp du fameux
Mourawief, et tout en partageant, peut-être, au fond du
cœur, les théories de ses victimes avait fait expédier ad
patres force insurgés. C’est en Pologne aussi, que Trépow
commença sa fortune.
» Est-ce une légende ou est-ce la vérité ? J’ai entendu
raconter souvent que le gouverneur de Saint-Pétersbourg
était un enfant trouvé, non sur la voie publique, mais sur
les marches d’un escalier. De là son nom. La condition
d’enfant trouvé en Russie est toute particulière ; elle n’a
rien d’inavouable. Le plus grand bâtiment de la ville, à
Saint-Pétersbourg, celui qu’on aperçoit le premier en
arrivant de la gare pour se diriger vers l’intérieur de la
ville, est l’édifice destiné aux petits êtres abandonnés, qui
y reçoivent, paraît-il, une bonne éducation et entrent
dans l’administration et dans l’armée.
» Trépow servit d’abord au Caucase, comme tant de
milliers d’autres Russes, et y acquit rapidement grades
sur grades jusqu’à celui de capitaine. C’est en cette
qualité qu’il fut envoyé à Varsovie au moment où
l’insurrection de Pologne éclatait. Des colonnes de
gendarmerie mobile furent organisées pour rechercher les
chefs de l’insurrection et surtout pour servir de
contrepoids aux « gendarmes pendeurs » du
gouvernement national, agents d’une sorte de Vehme, qui
frappait les traîtres et les fonctionnaires les plus détestés.
Trépow se signala en faisant la chasse à l’homme, et dans
ces jours de justice sommaire et d’exécution immédiate
sur simple constatation d’identité, il fut un des plus actifs
pourvoyeurs des pelotons d’exécution et de la potence.
C’est là aussi qu’il fit cet apprentissage de policier, qui
devait lui rendre de si grands services plus tard dans la
capitale, au poste qu’il occupe aujourd’hui. Pourtant, en
admettant que le gouvernement russe ait tenu tout
particulièrement à récompenser les aides-bourreaux de la
Pologne, la fortune de Trépow prit des proportions
fantastiques. On eût dit qu’une protection puissante,
mystérieuse et romanesque s’était attachée au nom de
celui dont l’origine était restée dans l’ombre, peut-être en
raison de cette origine.
» Dépassant rapidement ses supérieurs immédiats qui
traitaient en bien petit garçon à Varsovie le simple
capitaine de gendarmes, coup sur coup on apprit avec
stupeur et non sans jalousie, assurément, les différentes
phases de cette élévation qui rappelle la fortune de
Potemkin, de Menschikof et autres favoris des tsars.
Trépow sautait par-dessus les échelons de la hiérarchie
comme un cheval de course par-dessus une banquette
irlandaise. En très-peu de temps, il était devenu général
de division, aide de camp de l’empereur et gouverneur de
Saint-Pétersbourg. Ces fonctions donnent à celui qui les
occupe un pouvoir absolu sur tous les habitants de la
capitale. Tous les aubergistes, hôteliers, restaurateurs,
loueurs de voitures, etc., etc., et, dans un autre ordre
d’idées, les auteurs, les artistes sont dans sa main. Il
peut d’un trait de plume les priver de leurs ressources.
» Aucun étranger n’arrive à Saint-Pétersbourg sans
qu’immédiatement le gouverneur ne sache qui il est et ce
qu’il cherche sur les bords de la Neva. D’un trait de plume
aussi, M. Trépow peut faire reconduire l’étranger à la
frontière. Comme nous l’avons dit, il n’a de comptes à
rendre à personne, hors l’empereur, et les ministres ne
pourraient même pas soustraire un protégé à la vindicte
du gouverneur.
» Au point de vue administratif, les attributions du
gouverneur sont aussi étendues que celles du préfet de la
Seine, du conseil municipal et du conseil général réunies ;
sous ce rapport, au reste, Trépow n’a pas fait mauvais
usage de sa dictature. Grâce à son inexorable sévérité
agrémentée de coups de bâton appliqués au besoin aux
balayeurs, les rues de Saint-Pétersbourg sont aussi
propres que la température le permet. Le pavé et
l’éclairage sont régulièrement entretenus ; enfin on se
sent dans une ville européenne, tandis qu’il y a une
quinzaine d’années, malgré les magnifiques palais de
Catherine, malgré les quais de granit, la capitale de la
Russie laissait beaucoup à désirer sous le rapport de la
voirie. Ces petites réformes ont valu, dans le peuple
surtout, une certaine popularité au général. Celui-ci sait,
d’ailleurs, soigner la mise en scène. Il se montre
beaucoup dans sa troïka, filant rapidement comme le
vent ; aussi dit-on de lui comme du fameux solitaire,
« qu’il est partout, qu’il sait tout et voit tout ». Pour plus
d’un moujik, c’est par l’œil, toujours aux aguets, du
gouverneur, que le bon Dieu apprend tout ce qui se
passe. Dans les classes plus élevées de la société, au
contraire, Trépow compte beaucoup de contempteurs
mêlés à des envieux. Beaucoup se comporteraient aussi
brutalement que le général s’ils avaient sa place, qui
critiquent ses procédés. Peut-être ce sentiment n’a-t-il
pas été tout à fait étranger au verdict du jury.
» Nous ne croyons pas que cette décision ébranle la
situation du gouverneur. Il faudrait que l’empereur
renonçât subitement à une affection qui ne s’est pas
démentie depuis douze années, et que l’impératrice Marie
consentît à sacrifier le repos de ses nuits, puisqu’elle a
déclaré « que si Trépow ne veillait pas sur la ville, elle ne
dormirait pas tranquille ». Ajoutons, en passant, que
l’affection du tzar pour ce général n’est pas seulement
honorifique ; elle a valu au gouverneur des présents
superbes et entre autres une magnifique maison qui vaut
plus de 600,000 francs.
» Mais, dira-t-on, le tzar est un prince humanitaire ; il
a aboli la bastonnade et ne saurait tolérer davantage un
homme qui, en dépit de ses ordres, frappe les
prisonniers. Alexandre II a bien aboli la peine de mort, et
cependant on a fusillé et pendu en Pologne et à Khiva.
Alexandre II a proclamé la nécessité de la paix, et
cependant son gouvernement sort d’une guerre pour se
précipiter dans une autre. On peut bien alors supprimer la
bastonnade et garder Trépow. »
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