Hands-On Data Analysis with NumPy and pandas
eBook - ePub

Hands-On Data Analysis with NumPy and pandas

Implement Python packages from data manipulation to processing

  1. 168 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On Data Analysis with NumPy and pandas

Implement Python packages from data manipulation to processing

Book details
Book preview
Table of contents
Citations

About This Book

Get to grips with the most popular Python packages that make data analysis possible

Key Features

  • Explore the tools you need to become a data analyst
  • Discover practical examples to help you grasp data processing concepts
  • Walk through hierarchical indexing and grouping for data analysis

Book Description

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.

What you will learn

  • Understand how to install and manage Anaconda
  • Read, sort, and map data using NumPy and pandas
  • Find out how to create and slice data arrays using NumPy
  • Discover how to subset your DataFrames using pandas
  • Handle missing data in a pandas DataFrame
  • Explore hierarchical indexing and plotting with pandas

Who this book is for

Hands-On Data Analysis with NumPy and Pandas is for you if you are a Python developer and want to take your first steps into the world of data analysis. No previous experience of data analysis is required to enjoy this book.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Hands-On Data Analysis with NumPy and pandas by Curtis Miller in PDF and/or ePUB format, as well as other popular books in Informatik & Datenverarbeitung. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781789534245
Edition
1

Operations on NumPy Arrays

Now that we know how to create NumPy arrays, we can discuss the important topic of slicing NumPy arrays in order to access and manipulate subsets of array data. In this chapter, we will cover what every NumPy user should know about array slicing, arithmetic, linear algebra with arrays, and employing array methods and functions.

Selecting elements explicitly

If you know how to select subsets of Python lists, you know most of what you need to know about ndarray slicing. The elements of the array being indexed that correspond to the elements of the indexing object are returned in a new array. The most important aspect of indexing is to remember that there is more than one dimension, and the indexing method should be able to handle these other dimensions.
Remember the following points while selecting elements explicitly:
Separate the indexing objects for different dimensions with a comma; the object before the first comma shows how the first dimension is indexed. After the first comma comes the index for the second dimension, after the second comma comes the index for the third dimension, and so on.

Slicing arrays with colons

Indexing ndarray objects using colons works like indexing lists using colons. Just remember there are multiple dimensions now. Remember that when the spot before or after the colon is left blank, Python treats the index as extending to either the beginning or the end of the dimension. A second colon can be specified to instruct Python to, say, skip every other row or reverse the order of rows, depending on the number under the second colon.
The following points need to be remembered when slicing arrays with colons:
Let's see an example. First we load in NumPy and create an array:
Notice that what we created is a three-dimensional array. Now, this array is a bit complicated, so let's work with a two-dimensional 3 x 3 array instead:
We used the copy method here. A new object was returned, but that object isn't a new copy of the array; it is a view of the array's contents. So if we wish to create an independent copy, we will need to use the copy method when slicing as well, as we have seen before.
If we want to change an entry in this new array, say the second row and the second column's contents to Atilla, then we change this new array:
But we have not changed the original contents:
So, these are two independent copies of the data in the first array. Now let's explore some other slicing schemes.
Here, we see indexing using lists. What we do is create a list that corresponds to the first coordinate of every element from the object we wish to capture, and then we have a list for the second coordinate. So 1 and 0 correspond to one element that we wish to select; if this were a three-dimensional object, we would need a third list for the third coordinate:
We select elements from the upper-left corner using slicers:
Now, let's select elements from the middle column:
And, let's select elements from the middle column but we will not flatten the matrix and we'll keep its shape:
This is a one-dimensional object, but here we want a two-dimensional object. While it has only one column, it has one column and one row, as opposed to having only one row and columns don't make sense. Now let's select the last two rows of the middle column:
We reverse the row order:
If you look at the original object, you will see that these rules are happening in reverse order (compared to how they originally were ordered) and this means selecting odd number columns:
We can go to a more complex three-dimensional array and see si...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Setting Up a Python Data Analysis Environment
  7. Diving into NumPY
  8. Operations on NumPy Arrays
  9. pandas are Fun! What is pandas?
  10. Arithmetic, Function Application, and Mapping with pandas
  11. Managing, Indexing, and Plotting
  12. Other Books You May Enjoy