5 (1)

5 (1)

#### Overview of this book

Python, a multi-paradigm programming language, has become the language of choice for data scientists for visualization, data analysis, and machine learning. Hands-On Data Analysis with NumPy and Pandas starts by guiding you in setting up the right environment for data analysis with Python, along with helping you install the correct Python distribution. In addition to this, you will work with the Jupyter notebook and set up a database. Once you have covered Jupyter, you will dig deep into Python’s NumPy package, a powerful extension with advanced mathematical functions. You will then move on to creating NumPy arrays and employing different array methods and functions. You will explore Python’s pandas extension which will help you get to grips with data mining and learn to subset your data. Last but not the least you will grasp how to manage your datasets by sorting and ranking them. By the end of this book, you will have learned to index and group your data for sophisticated data analysis and manipulation.
Title Page
Packt Upsell
Contributors
Preface
Free Chapter
Setting Up a Python Data Analysis Environment
Diving into NumPY
Operations on NumPy Arrays
pandas are Fun! What is pandas?
Arithmetic, Function Application, and Mapping with pandas
Managing, Indexing, and Plotting
Other Books You May Enjoy
Index

## Arithmetic

Let's see an example. The first thing we'll do is start up pandas and NumPy.

In the following screenshot, we have two series, `srs1` and `srs2`:

`srs1` has an index that goes from 0 to 4, whereas `srs2` has an index that goes from 0 to 3, skips 4, and then goes to 5. These two series are technically the same length, but that doesn't necessarily mean that the elements will match up as you might expect. For example, let's consider the following code. What happens when we add `srs1` and `srs2`?

Two NaNs were produced. That was because, for elements 0 to 3, there were elements in both series that could be matched up, but for 4 and 5, there were non-equivalent elements for each index in both series. This is also going to be the case when we multiply, shown as follows:

Or if we were to exponentiate, as follows:

That being said, Boolean arithmetic is different. In this case, comparison is done element by element, as you would normally expect. In fact, it seems that Boolean comparison doesn't care at...