Skip to Content
Numerical Computing with Python
book

Numerical Computing with Python

by Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim
December 2018
Beginner to intermediate
682 pages
18h 1m
English
Packt Publishing
Content preview from Numerical Computing with Python

How it works...

Most DataFrames will not have columns of booleans like our movie dataset. The most straightforward method to produce a boolean Series is to apply a condition to one of the columns using one of the comparison operators. In step 2, we use the greater than operator to test whether or not the duration of each movie was more than two hours (120 minutes). Steps 3 and 4 calculate two important quantities from a boolean Series, its sum and mean. These methods are possible as Python evaluates False/True as 0/1.

You can prove to yourself that the mean of a boolean Series represents the percentage of True values. To do this, use the value_counts method to count with the normalize parameter set to True to get its distribution:

>>> movie_2_hours.value_counts(normalize=True) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Numerical Computing with NumPy

Mastering Numerical Computing with NumPy

Umit Mert Cakmak, Tiago Antao, Mert Cuhadaroglu

Publisher Resources

ISBN: 9781789953633OtherOtherErrata Page