Book Image

Hands-On Data Analysis with NumPy and Pandas

By : Curtis Miller
5 (1)
Book Image

Hands-On Data Analysis with NumPy and Pandas

5 (1)
By: Curtis Miller

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.
Table of Contents (12 chapters)

Arithmetic and linear algebra with arrays


Now that we have seen how to create and access information with NumPy arrays, let's cover some of the numerical operations you can do with arrays. In this section, we will be discussing arithmetic using NumPy arrays; we also discuss using NumPy arrays for linear algebra.

Arithmetic with two equal-shaped arrays

Arithmetic with NumPy arrays is always done component-wise. This means that, if we have two matrices that have equal shapes, an operation such as addition is done by matching corresponding components in the two matrices and adding them. This is true for any arithmetic operation, be it addition, subtraction, multiplication, division, powers, or even logical operators.

Let's see an example. First, we create two arrays of random data:

While I explain these ideas in terms of arithmetic involving two arrays, it can involve arrays and scalars as we see here, where we add 100 to every element in arr1:

Next, we divide every element in arr1 by 2:

Next, we...